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

Fetch configuration content from PR ref #8

Merged
merged 2 commits into from
Aug 23, 2019

Conversation

eebs
Copy link
Contributor

@eebs eebs commented Aug 16, 2019

Fixes #6

When fetching the configuration content from the file specified by configuration-path, we should load the content from the ref of the PR.

By default, repos.getContents will use the repository's default branch if no ref is specified.

When first configuring this action, assuming the configuration file is added in the same PR as the action, the configuration file will not exist on the default branch. This causes an HttpError: Not Found to occur when attempting to load the configuration from the default branch.

This commit updates the call to getContents to add the ref parameter, set to the GITHUB_SHA value from the context. This will cause the action to load the contents of the configuration file from the ref of the PR, rather than the default branch.


This PR also updates the packages to use version 1.0.0 of all the toolkit action packages, as they were using local files before.

I noticed that src/main.ts is not formatted according to the prettier rules. I'm happy to open another PR that applies prettier to the current source. I had to disable prettier during implementation of this commit in order to keep the changes relevant to this PR.

Fixes actions#6

When fetching the configuration content from the file specified by
`configuration-path`, we should load the content from the ref of the PR.

By default, `repos.getContents` will [use the repository's default
branch][1] if no `ref` is specified.

When first configuring this action, assuming the configuration file is
added in the same PR as the action, the configuration file will not
exist on the default branch. This causes an `HttpError: Not Found` to
occur when attempting to load the configuration from the default branch.

This commit updates the call to `getContents` to add the `ref`
parameter, set to the `GITHUB_SHA` value from the context. This will
cause the action to load the contents of the configuration file from the
ref of the PR, rather than the default branch.

---

This PR also updates the packages to use version 1.0.0 of all the
toolkit action packages, as they were using local files before.

I noticed that `src/main.ts` is not formatted according to the prettier
rules. I'm happy to open another PR that applies prettier to the current
source. I had to disable prettier during implementation of this commit
in order to keep the changes relevant to this PR.

[1]: https://developer.github.com/v3/repos/contents/#get-contents
@dougnukem
Copy link

Why doesn't the action access the configuration from the local workspace git checkout rather than going to the github API to fetch the file?

@eebs
Copy link
Contributor Author

eebs commented Aug 20, 2019

Why doesn't the action access the configuration from the local workspace git checkout rather than going to the github API to fetch the file?

There actually isn't a local checkout of the repository. This action only uses the event payload and the API to label the PR.

Copy link
Contributor

@damccorm damccorm left a comment

Choose a reason for hiding this comment

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

This looks great, thanks for the contribution!

package.json Outdated Show resolved Hide resolved
@@ -92,7 +92,8 @@ async function fetchContent(
const response = await client.repos.getContents({
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we maybe want to retry on the default branch if this 404's? The scenario I'm concerned about is:

  1. User X branches repo
  2. This action gets merged into master
  3. User X PRs, but is out of sync with master

No label would get applied at this point if they hadn't synced with master yet, even if they sync. I know this is kinda an edge case, but its most likely to crop up the first couple of times the action is run and isn't a great first experience.

Copy link
Contributor Author

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'd agree with retrying on the default branch. My feeling is that workflows/actions should only run against the code in the ref/sha they are committed to. I think I'd be surprised if my branch used actions/configuration from a different branch.

I think the scenario you described is fairly unlikely and has an obvious remedy (rebase/merge master).

What do you think of shipping this as-is, and making the change if we get feedback from the community?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the scenario you described is fairly unlikely and has an obvious remedy (rebase/merge master).

Yeah, you're right - got this one confused with another action and was thinking that it only got triggered on a PR being opened, that's not right though.

Lets ship, I don't think we need this - thanks for pushing back.

@damccorm damccorm merged commit b726232 into actions:master Aug 23, 2019
@damccorm
Copy link
Contributor

Published!

@eebs eebs deleted the ek-fetch-contents-from-pr-ref branch August 23, 2019 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HttpError: Not Found when run with new yml config
3 participants