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

Add [Github] pull request state badge #1207

Closed
wants to merge 1 commit into from
Closed

Add [Github] pull request state badge #1207

wants to merge 1 commit into from

Conversation

ivanovyordan
Copy link

URL pattern:

/github/pr-state/<user>/<repo>/<issueId>.<format>

The issue (which ID is provided in the URL) must be a pull-request.

The following states are handled:
inaccessible (lightgrey) if the request failed or the response was not a json-formatted issue
closed (red) if the PR is closed and not merged
merged (Github purple-ish) if the PR is closed and merged
mergeable (green) if the PR is open and clean (build OK, no conflicts detected, rebased on latest version of the base branch)
unstable (yellow) if the PR is open but unstabe
has conflicts (red) if the PR is open but not mergeable (conflicts with base branch detected)
unknown (lightgrey) if the PR is open but the mergeability is not computed yet (more details here)

Related PR: GH-806

@paulmelnikow paulmelnikow added the service-badge New or updated service badge label Oct 26, 2017
@paulmelnikow paulmelnikow changed the title Add pull request state badge Add [Github] pull request state badge Oct 27, 2017
Copy link
Member

@paulmelnikow paulmelnikow left a comment

Choose a reason for hiding this comment

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

Thanks so much for reviving this work! I left some comments.

@@ -9,5 +9,6 @@
"grey": { "colorB": "#555" },
"gray": { "colorB": "#555" },
"lightgrey": { "colorB": "#9f9f9f" },
"lightgray": { "colorB": "#9f9f9f" }
"lightgray": { "colorB": "#9f9f9f" },
"purple": { "colorB": "#6f42c1" }
Copy link
Member

Choose a reason for hiding this comment

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

Is this github's merged purple? If we do add a named "purple" it probably should not be github's. You can hard-code it in the badge code instead.

// pull request state

t.create('Pull request state, regular case')
.get('/pr-state/badges/shields/578.json')
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this /pulls/state for consistency with e.g. https://img.shields.io/github/pulls/detail/comments/badges/shields/1112.svg.

.expectedJSONTypes(Joi.object().keys({
name: 'pull request',
value: Joi.string().regex(/^\w+/)
}));
Copy link
Member

Choose a reason for hiding this comment

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

Could you get these tests passing? Otherwise they look good!

<td>
<code>https://img.shields.io/github/pr-state/badges/shields/6.svg</code></td>
</tr>
<tr>
Copy link
Member

Choose a reason for hiding this comment

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

After #1163 try.html is generated, so could you please make these changes in lib/all-badge-examples.js instead, and then run npm run build?

try.html will no longer be tracked after #1194.

badgeData.logo = getLogo('github', data);
}

githubAuth.request(request, apiUrl, {}, function (err, res, buffer) {
Copy link
Member

Choose a reason for hiding this comment

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

You can use an arrow function here: (err, res, buffer) =>

try {
const pr = JSON.parse(buffer);
let colorscheme = '';
let status = '';
Copy link
Member

Choose a reason for hiding this comment

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

It would be clearer what's happening with these declarations let colorscheme if you moved them just before their switch statements. Also you can just write let colorscheme;. It doesn't help to assign an empty string.

let colorscheme = '';
let status = '';

const responseIsIssueLike = pr.hasOwnProperty('state') &&
Copy link
Member

Choose a reason for hiding this comment

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

How about calling it responseIsValid to indicate this code is validating the response?

.get('/pr-state/badges/shields/578.json')
.expectJSONTypes(Joi.object().keys({
name: Joi.equal('pull request state'),
value: Joi.equal('closed', 'merged', 'mergeable', 'has conflicts', 'need rebase')
Copy link
Member

Choose a reason for hiding this comment

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

This will always be 'merged'.

.get('/pr-state/badges/shields/-1.json')
.expectJSONTypes(Joi.object().keys({
name: Joi.equal('pull request state'),
value: Joi.equal('inaccessible')
Copy link
Member

Choose a reason for hiding this comment

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

Since these are both literals you can simplify this to .expectJSON({ ... })

.get('/pr-state/badges/shields/6.json')
.expectedJSONTypes(Joi.object().keys({
name: 'pull request',
value: Joi.string().regex(/^\w+/)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I understand the purpose of this test. Could you clarify? ^^

@ivanovyordan
Copy link
Author

@paulmelnikow Thanks for the great review. Will address all the notes ASAP.

@paulmelnikow
Copy link
Member

Hey, just thought I'd follow up. Could you address these comments when you have a chance? Also, please merge master into your branch to resolve the conflicts.

@ivanovyordan
Copy link
Author

Yes. I was traveling a lot lately. Will do it in the next few days.

@paulmelnikow paulmelnikow added the on-hold Deferred in favor of another approach, blocked on preceding efforts, stale, or abandoned label Nov 27, 2017
@paulmelnikow
Copy link
Member

I'd love to get this in. Feel free to reopen it when you're ready!

Anyone else reading this who want this implemented, you can grab the commits from the pull request branch using git fetch origin pull/1207/head:pr-1207, address the comments, and reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on-hold Deferred in favor of another approach, blocked on preceding efforts, stale, or abandoned service-badge New or updated service badge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants