Fixed undefined source stats for private repositories
This commit is contained in:
parent
2d66c7ed22
commit
e473a1fedc
File diff suppressed because one or more lines are too long
|
|
@ -149,7 +149,7 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script src="{{ base_url }}/assets/javascripts/application-6b599127bc.js"></script>
|
<script src="{{ base_url }}/assets/javascripts/application-6b4ff16fa7.js"></script>
|
||||||
<script>app.initialize({url:{base:"{{ base_url }}"}})</script>
|
<script>app.initialize({url:{base:"{{ base_url }}"}})</script>
|
||||||
{% for path in extra_javascript %}
|
{% for path in extra_javascript %}
|
||||||
<script src="{{ path }}"></script>
|
<script src="{{ path }}"></script>
|
||||||
|
|
|
||||||
|
|
@ -32,15 +32,22 @@ export default class GitHub extends Abstract {
|
||||||
* Retrieve repository information from GitHub
|
* Retrieve repository information from GitHub
|
||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
|
*
|
||||||
|
* @property {string} name_ - Name of the repository
|
||||||
|
*
|
||||||
* @param {(string|HTMLAnchorElement)} el - Selector or HTML element
|
* @param {(string|HTMLAnchorElement)} el - Selector or HTML element
|
||||||
*/
|
*/
|
||||||
constructor(el) {
|
constructor(el) {
|
||||||
super(el)
|
super(el)
|
||||||
|
|
||||||
/* Adjust base URL to reach API endpoints and remove trailing slash */
|
/* Extract user and repository name from URL, as we have to query for all
|
||||||
this.base_ = this.base_
|
repositories, to omit 404 errors for private repositories */
|
||||||
.replace("github.com/", "api.github.com/repos/")
|
const [, user, name] = /^.+github\.com\/([^\/]+)\/([^\/]+).*$/
|
||||||
.replace(/\/$/, "")
|
.exec(this.base_)
|
||||||
|
|
||||||
|
/* Initialize base URL and repository name */
|
||||||
|
this.base_ = `https://api.github.com/users/${user}/repos`
|
||||||
|
this.name_ = name
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -52,10 +59,13 @@ export default class GitHub extends Abstract {
|
||||||
return fetch(this.base_)
|
return fetch(this.base_)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
return [
|
const repo = data.find(item => item.name === this.name_)
|
||||||
`${this.format_(data.stargazers_count)} Stars`,
|
return repo
|
||||||
`${this.format_(data.forks_count)} Forks`
|
? [
|
||||||
]
|
`${this.format_(repo.stargazers_count)} Stars`,
|
||||||
|
`${this.format_(repo.forks_count)} Forks`
|
||||||
|
]
|
||||||
|
: []
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue