Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor [GitHubCommitActivity] to switch to v4/GraphQL API #6959

Merged
merged 2 commits into from
Aug 29, 2021

Conversation

calebcartwright
Copy link
Member

Resolves #2704

@calebcartwright calebcartwright added service-badge New or updated service badge keep-service-tests-green Related to fixing failing tests of the services labels Aug 28, 2021
@shields-cd shields-cd temporarily deployed to shields-staging-pr-6959 August 28, 2021 02:39 Inactive
@shields-ci
Copy link

shields-ci commented Aug 28, 2021

Messages
📖 ✨ Thanks for your contribution to Shields, @calebcartwright!

Generated by 🚫 dangerJS against 960fa14

}

static examples = [
{
title: 'GitHub commit activity',
// Override the pattern to omit the deprecated interval "4w".
pattern: ':interval(y|m|w)/:user/:repo',
pattern: ':interval(y|m|w)/:user/:repo/',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was debating whether to add another example that showed the ability to specify a branch/ref but that ties in to a broader question asked below

$since: GitTimestamp!
) {
repository(owner: $user, name: $repo) {
object(expression: $branch) {
Copy link
Member Author

@calebcartwright calebcartwright Aug 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best I can tell this value is used in a call to git's rev-list directly or indirectly via rev-parse and is a required part of the query. My understanding is that defaulting to this to HEAD means it'll work with the default branch in the target repo regardless of what that branch is named, and seems like a good idea given we must provide something.

One thing I wasn't clear on was whether the existing v3 API did the same internally or if it spanned across all the branches. At the moment the v3 is still "down" (HTTP 202 - processing) so I can't really compare the results to check for any differences. I think if we go this route with this type of query then it makes sense to surface up the ref that's used here as a route parameter so that users can specify their preference.

(edit: switched to HEAD over FETCH_HEAD for default)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs are slightly unclear on this, but https://docs.github.com/en/rest/reference/repos#statistics says the stats match the graphs in the front end (e.g: https://github.com/badges/shields/graphs/contributors ). My interpretation is they do only show commits to the default branch. I think this assumption is good

if (interval === 'y') {
now.setUTCFullYear(now.getUTCFullYear() - 1)
} else if (interval === 'm' || interval === '4w') {
now.setUTCDate(now.getUTCDate() - 30)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The classic fun question of "what is a month, really?" 😆 I know we still have momentjs in our dep tree but I opted to avoid using it to prevent from increasing our dependence on it due to #5573.

IMO showing the commit activity for the last 30 days is a reasonable time period to cover both of these intervals, but suppose we could try to do something more complex. I feel like some of the complexity we had before was more due to the nature of the v3 API response that just gave us total counts in weekly slices, but lmk if folks have any concerns with treating month as the last 30 days

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other badges where we are making the same assumption e.g:

month: {
base: 'packagecontrol/dm',
messageSuffix: '/month',
transform: resp => {
const platforms = resp.installs.daily.data
let downloads = 0
platforms.forEach(platform => {
// total for the first 30 days
for (let i = 0; i < 30; i++) {
downloads += platform.totals[i]
}
})
return downloads
},
name: 'PackageControlDownloadsMonth',
},

dm: {
startDate: endDate => moment(endDate).subtract(30, 'days'),
suffix: '/month',

const periodMap = {
dm: {
api_field: '30d',
suffix: '/month',
},

dm: {
limit: 30,
messageSuffix: '/month',
},

I don't know where it fits in the docs, but I'd be happy to document somewhere that if the upstream api doesn't explicitly provide stats for "month", we assume month = 30 days and formalise this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, glad to be in good company!

@calebcartwright
Copy link
Member Author

Discovered an issue poking around the review app, can't seem to convert the PR back to a draft but working on it

@chris48s
Copy link
Member

For reference, you should have a button under "reviewers"

Screenshot at 2021-08-28 16-05-21

@calebcartwright
Copy link
Member Author

For reference, you should have a button under "reviewers"

TIL 😄

@calebcartwright calebcartwright temporarily deployed to shields-staging-pr-6959 August 28, 2021 15:11 Inactive
@calebcartwright
Copy link
Member Author

calebcartwright commented Aug 28, 2021

Comparisons and commentary between the activity shown with this vs. current below. One key difference between the v4 results vs the v3 results is that v4 is currently using an exact date and time window, vs. whole day rounding, so there are slightly different windows at the date boundaries

weekly

https://img.shields.io/github/commit-activity/w/badges/shields

https://shields-staging-pr-6959.herokuapp.com/github/commit-activity/w/badges/shields/

These happen to produce the same value (at the moment anyway), but that's largely just a coincidence since our current badge displays the total commits from the prior full week which is something we had to do to account for the structure of the v3 API response to avoid only showing 2-3 days worth of commits on some days earlier in the week.

image

Monthly

In addition to the start-of-day delta, there's also the 30 day window in this approach vs. the calculated month estimate we had before

eslint

https://img.shields.io/github/commit-activity/m/eslint/eslint

https://shields-staging-pr-6959.herokuapp.com/github/commit-activity/m/eslint/eslint

shields

https://img.shields.io/github/commit-activity/m/badges/shields

https://shields-staging-pr-6959.herokuapp.com/github/commit-activity/m/badges/shields

Yearly

eslint

https://img.shields.io/github/commit-activity/y/eslint/eslint

https://shields-staging-pr-6959.herokuapp.com/github/commit-activity/y/eslint/eslint

shields

https://img.shields.io/github/commit-activity/y/badges/shields

https://shields-staging-pr-6959.herokuapp.com/github/commit-activity/y/badges/shields

@calebcartwright calebcartwright temporarily deployed to shields-staging-pr-6959 August 28, 2021 15:29 Inactive
Copy link
Member

@chris48s chris48s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the core point of this badge is to give a ballpark of how active a repo is rather than to display a precise value. Consistently working with very slightly different assumptions (which might yield slightly different numbers for some users) is better than broken for some users.

@calebcartwright
Copy link
Member Author

calebcartwright commented Aug 29, 2021

I think the core point of this badge is to give a ballpark of how active a repo is rather than to display a precise value. Consistently working with very slightly different assumptions (which might yield slightly different numbers for some users) is better than broken for some users.

Yup completely agreed on this and the documentation front as well. If it starts popping up as a common question/source of confusion then I'll clarify, perhaps as a Discussion topic or somewhere in our markdown docs, as well as inline docs in the badge builder window.

@repo-ranger repo-ranger bot merged commit 76ca283 into master Aug 29, 2021
@repo-ranger repo-ranger bot deleted the gh-commit-activity-to-v4 branch August 29, 2021 17:59
acusti added a commit to acusti/uikit that referenced this pull request Sep 26, 2021
looks like the github commit activity badges have been fixed: badges/shields#6959
acusti added a commit to acusti/uikit that referenced this pull request Sep 26, 2021
looks like the github commit activity badges have been fixed: badges/shields#6959
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep-service-tests-green Related to fixing failing tests of the services service-badge New or updated service badge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GitHub yearly commit activity badge is flaky
4 participants