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

feat: Allow warning only if secrets aren't available #22

Merged
merged 16 commits into from Jul 23, 2020
Merged

feat: Allow warning only if secrets aren't available #22

merged 16 commits into from Jul 23, 2020

Conversation

baywet
Copy link
Contributor

@baywet baywet commented Jul 20, 2020

As you can see in https://github.com/eps1lon/actions-label-merge-conflict/runs/890095723?check_suite_focus=true#step:9:7 the action fails when a PR which comes from a fork is updated (push to the source branch).
It seems to be because in that case the github.context.repo reference points to the fork and not the upstream, making the subsequent queries wrong.
This pull request checks for the issue's information first (if any) and falls back on the repo information

@baywet
Copy link
Contributor Author

baywet commented Jul 20, 2020

@eps1lon
Copy link
Owner

eps1lon commented Jul 20, 2020

I'm pretty sure this is due to fork PRs having no access to github secrets. Let's see what CI says. Though github actions seem to be down at the moment.

@eps1lon
Copy link
Owner

eps1lon commented Jul 20, 2020

Though this might be a bit hidden under "Example usage" in the README.md:

WARNING: PRs from forks don't have access to screts.
You might want to skip this action on pull_requests which means
the label might not reflect the current state of the PR until
another push on main

@baywet
Copy link
Contributor Author

baywet commented Jul 20, 2020

Yeah I just found that https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#permissions-for-the-github_token as well
Could we at least fail gracefully or provide a option to do so?

@eps1lon
Copy link
Owner

eps1lon commented Jul 20, 2020

Could we at least fail gracefully or provide a option to do so?

Yeah. I'd prefer a more helpful error message and an option to fallback to a warning. Warnings by default are usually missed.

@baywet
Copy link
Contributor Author

baywet commented Jul 20, 2020

done. Some context on checking both on 403 and 404 is because of that https://developer.github.com/v3/troubleshooting/
I think it's still failing because it's testing with main and not this branch as Run eps1lon/actions-label-merge-conflict@main would lead me to think https://github.com/eps1lon/actions-label-merge-conflict/pull/22/checks?check_run_id=891129860#step:10:1

sources/main.ts Outdated
throw new Error(`error adding "${label}": ${error}`);
if ((error.status === 403 || error.status === 404) && error.message.endsWith(`Resource not accessible by integration`)) {
core.warning(`could not remove label`);
core.info(`Worflows can't access secrets and have read-only access to upstream when they are triggered by a pull request from a fork, [more information](https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#permissions-for-the-github_token)`);
Copy link
Owner

Choose a reason for hiding this comment

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

Is there a reason for two separate messages on different levels? Can we squash these into a single one?

I'd still prefer a failure by default with an option to warn-only. PRs not having access to secrets isn't commonly know which is apparent from this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just to be clear, you want everything in the warning? The reason I had separated it is because I didn't want the thing to be too verbose, but I'm happy to review that.

I'm not sure if I'd fail by default, maybe warn by default (warning shows in the gates) with an option to fail. I feel like failing by default is a huge blocker for people for something they can't do anything about at the moment. What about warn by default with an option to fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eps1lon any opinion on the above? :)

Copy link
Owner

Choose a reason for hiding this comment

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

Yep everything in one message if it is related.

I do have a strong opinion on the failure. A warning will mark the check as green, no? If something isn't working then I'd always prefer a fail because warnings are usually missed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I remember the check mark is green in the gate (PR recap) but you get some orange markers in the worklow run (once you click on details)

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah. The default assumption is that it adds a label. If something isn't functioning then it should throw not warn. I'll definitely accept an option that downgrades it to a warning (or simply extends the error message). But the failure by default should stay.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fair enough, updated

dist/index.js Outdated Show resolved Hide resolved
@baywet baywet requested a review from eps1lon July 21, 2020 14:27
@eps1lon eps1lon changed the title - fixes a bug where reference to owner and repo would be wrong in some context feat: Allow warning only if secrets aren't available Jul 23, 2020
Copy link
Owner

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

Could you update the README with that new parameter. Then this should be good to go.

@baywet
Copy link
Contributor Author

baywet commented Jul 23, 2020

@eps1lon already did? b937291

@eps1lon
Copy link
Owner

eps1lon commented Jul 23, 2020

@eps1lon already did? b937291

Happened after I started the review. GitHub and state machines 🤷

Screenshot from 2020-07-23 19-55-53

@eps1lon
Copy link
Owner

eps1lon commented Jul 23, 2020

Actually makes sense to enable this flag on this repository for integration test.

@baywet
Copy link
Contributor Author

baywet commented Jul 23, 2020

Actually makes sense to enable this flag on this repository for integration test.

done!

@eps1lon
Copy link
Owner

eps1lon commented Jul 23, 2020

Works like a charm. Passes with the action on this branch but fails on master as expected. Thanks for sticking with it!

@eps1lon eps1lon added the enhancement New feature or request label Jul 23, 2020
@eps1lon eps1lon merged commit 3ab41d0 into eps1lon:main Jul 23, 2020
@baywet
Copy link
Contributor Author

baywet commented Jul 23, 2020

Works like a charm. Passes with the action on this branch but fails on master as expected. Thanks for sticking with it!

thanks for driving it to it's best version!
With this one and #21 merged, you should probably rebuild to get the JS updated.

When do you expect it to be live?

@baywet baywet deleted the bugfix/owner-repo-reference branch July 23, 2020 18:30
@eps1lon
Copy link
Owner

eps1lon commented Jul 23, 2020

When do you expect it to be live?

Should be live. You could always use the latest version on main with eps1lon/actions-label-merge-conflict@main or pin to a single commit should work as well eps1lon/actions-label-merge-conflict@3ab41d0e73426c19d5dcc31bc71e8571796f4564

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants