-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
add support for [GitHubActions] via API #3913
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
Conversation
@@ -185,7 +185,8 @@ class GithubApiProvider { | |||
baseUrl, | |||
headers: { | |||
'User-Agent': 'Shields.io', | |||
Accept: 'application/vnd.github.v3+json', | |||
Accept: | |||
'application/vnd.github.v3+json, application/vnd.github.antiope-preview+json', | |||
Authorization: `token ${tokenString}`, | |||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was the overriding of provided options deliberate here? I had to add the alternative media type required for this API here as it wasn't working from the service class due to the merge order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure there is an open issue about the way we're merging options, but I can't find it for the life of me.
We often merge in the other order e.g:
shields/core/base-service/base-json.js
Lines 43 to 46 in c9cd77a
const mergedOptions = { | |
...{ headers: { Accept: 'application/json' } }, | |
...options, | |
} |
but the downside of this is if we want to pass an extra header, we have to re-add Accept: 'application/json'
(because the spread operation doesn't nest, if you see what I mean)
I suspect the reason we've done it in the other order here is so that if we pass any header, its not going to overwrite the Authorization
header.
In general, we need a more sophisticated merge starategy for these options
objects.
|
check_suites: Joi.array() | ||
.items( | ||
Joi.object({ | ||
status: Joi.string().required(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably try to use a stricter validation here for status and conclusion, although I've intentionally kept these at Joi.string()
. AFAICT, GitHub apps can update the list of possible status values that they use, which would flow through here (since this API returns all Check Suites, not just GH Actions Check Suites).
I believe that if we tried to restrict the allowed strings for these fields that we'd inevitably end up with users receiving "invalid response data" badges
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I think GH Actions is sufficiently flexible that its hard to reliably require something more restrictive here
Failing service tests were other unrelated GitHub badge tests (and didn't fail in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This overall looks good to me. I've left a few questions and suggestions inline. 👍
I'm more in favour of this API approach rather than the badge scraping one suggested in #3898. We've often had problems with badge scrapping in the past where the badge format was suddenly changed and broke our implementation. APIs are less likely to change (apart for preview features though) and hopefully they will expand the information to include things such as workflow names.
static render({ status, conclusion }) { | ||
if (status !== 'completed') { | ||
return { | ||
message: 'in progress', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in progress
should probably be added to the list of otherStatuses
in build-status.js. The test 'valid repo and ref' may occasionally fail otherwise. I would also suggest using renderBuildStatusBadge
for the 'in progress' value as well: it won't change anything with the current implementation, but if ever we decide to change the colour or something else, this build badge will automatically be covered as well. 😉
@@ -185,7 +185,8 @@ class GithubApiProvider { | |||
baseUrl, | |||
headers: { | |||
'User-Agent': 'Shields.io', | |||
Accept: 'application/vnd.github.v3+json', | |||
Accept: | |||
'application/vnd.github.v3+json, application/vnd.github.antiope-preview+json', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... May be worth documenting what the second accept value is for.
} | ||
|
||
transform(json) { | ||
if (json.total_count === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this extra check? Wouldn't the if (!actionsSuite)
get us covered as well?
Thanks for reviewing @PyvesB! I'm most likely going to just close this PR. I understand (and agree with) the preference for the API over badge scraping, but this approach simply isn't viable without the ability to utilize the workflow name (it's as core as being able to specify the GH owner and repo). The badge scraping approach is the only option that's available right now, and I've updated that PR with more detail in #3898 (comment). The Check Suite and Status APIs are not specific Actions/Workflow, but perhaps GitHub will eventually roll out Actions/Workflow APIs that we could switch to down the road. However, IMO we should proceed with the badge scraping approach as there is a huge community demand for this badge that we can meet, today, with that approach. |
Could we simply ask for the workflow name feature on the GitHub community forums? GitHub staff have been quite good at solving issues and responding to user queries regarding GitHub actions. I will look at the other PR in the evening. |
This feature request may well do the trick when implemented: https://github.community/t5/GitHub-API-Development-and/How-to-retrieve-the-full-list-of-Actions-workflow-runs-shown-on/m-p/39171 |
Closing this as #3898 has been merged and deployed |
Refs #2574. An alternative approach to #3898 that leverages the GH v3 Check Suites API instead of badge scraping the native GH Workflow result badge.
Although I still prefer this approach to #3898, there is one downside in instances where a repo has more than one Workflow running on a given ref (branch, etc.) vs. #3898.
In such a scenario, the response from the check-suites will include multiple records for each Workflow but there's no way to associate the record in the API response to a named Workflow, at least not that I've been able to find. For example, https://api.github.com/repos/actions/setup-python/commits/master/check-suites
The badge scraping approach in #3898 does allow the user to explicitly specify which Workflow they want by workflow name, but it only works on the master branch. The API approach allows the user to pick the branch/ref, but not the specific workflow by name