Added github check for accidental assignment submission#152
Added github check for accidental assignment submission#152adamblanchard wants to merge 6 commits into
Conversation
| - name: Check PR is a fork | ||
| id: check_fork | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const pr = context.payload.pull_request; | ||
| const isFork = pr.head.repo && pr.head.repo.id !== pr.base.repo.id; | ||
| console.log(`From fork? ${isFork}`); | ||
|
|
||
| core.setOutput('should_comment', isFork); | ||
|
|
||
| - name: Comment assignment instructions for trainees | ||
| if: steps.check_fork.outputs.should_comment == 'true' |
There was a problem hiding this comment.
I suspect that all of this could replaced by something like:
| - name: Check PR is a fork | |
| id: check_fork | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const pr = context.payload.pull_request; | |
| const isFork = pr.head.repo && pr.head.repo.id !== pr.base.repo.id; | |
| console.log(`From fork? ${isFork}`); | |
| core.setOutput('should_comment', isFork); | |
| - name: Comment assignment instructions for trainees | |
| if: steps.check_fork.outputs.should_comment == 'true' | |
| - name: Comment assignment instructions for trainees | |
| if: pull_request.head.fork == 'true' |
but I'm not sure of the exact syntax at this exact moment. Would be nice if it could be simplified, though.
There was a problem hiding this comment.
I originally used pull_request.head.fork and i couldn't get it to work. I can check my notes later to see if I can remember why. But happy to simplify, for sure!
Co-authored-by: rve.rc <rachel@rachelevans.org>
| uses: thollander/actions-comment-pull-request@v3 | ||
| continue-on-error: true | ||
| with: | ||
| message: | |
There was a problem hiding this comment.
Given the requirements here (i.e. very simple: just append a comment), I think that this could be simplified to something like:
| uses: thollander/actions-comment-pull-request@v3 | |
| continue-on-error: true | |
| with: | |
| message: | | |
| run: | | |
| gh pr comment --body-file /dev/stdin <<COMMENT |
(and with an appropriate COMMENT end marker)
which, because of not having the extra dependency, would have the benefits of being slightly more efficient, and more secure.
|
I had a play with this. Resulting code: https://github.com/rvedotrc/no-fork-test/blob/main/.github/workflows/assignment-check.yml In action (PR from fork to original): rvedotrc/no-fork-test#13 In action (PR from original to original): rvedotrc/no-fork-test#14 The differences:
|
|
@adamblanchard @rvedotrc I do not get a sense that there is a point to check whether submission is coming from a fork or not. |
|
Thanks both @rvedotrc @shpomp for exploring this too. The idea behind the fork check is the simplest way to assume if it is an assignment or not. All trainees need to submit via their fork, so this check will run in that case. If it is against the base repo (e.g. our template) they did it wrong and need a comment to help. We're also assuming that anyone who wants to actually contribute to the template (e.g. staff, mentors), will very likely be in our org and most likely clone it (e.g no fork). In the case that a mentor does fork and contribute, they also get a little prompt at the bottom of the message to reach out. They should be in our org/curriculum-crew anyway, so it's not a bad point to prompt them. Also, the number of times trainees make these PRs is like 45 a week, for three teams. The times a mentor might make a PR in the first place, never mind from a fork, is very very small in comparison. So i'm fine with this solution mostly taking care of the trainee case. Looking through all three of our ideas, I think @rvedotrc you have simplified it amazingly 👏 , and we should go with this route for now as a solution for the immediate challenge. I will update this PR with your solution. New ideas welcome to be iterated on afterwards, as always👌 |
|
Okies, this is ready for re-review. The only thing i changed was the name of the action, since it was a bit misleading to see it skipped while being called "assignment check" since it did actually check if it was an assignment already. |
| @@ -0,0 +1,27 @@ | |||
| # Check whether a PR is from a fork (likely a trainee). | |||
| # If from a fork, add a comment reminding the trainee about the correct submission process. | |||
| name: Assignment Comment | |||
There was a problem hiding this comment.
Probably a good idea to rename the yml file to match
|
|
||
| If so, you are incorrectly creating a pull request to the wrong repo. Please follow these [step by step instructions](https://github.com/HackYourFuture-CPH/hyf-assignment-template?tab=readme-ov-file#2-submission-process), and remember to close this PR. | ||
|
|
||
| (If you are a mentor, and are trying to contribute, reach out in #mentorroom for help.) |
There was a problem hiding this comment.
| (If you are a mentor, and are trying to contribute, reach out in #mentorroom for help.) | |
| (If you are a mentor, and you are trying to contribute, then please reach out in #mentorroom for help.) |
Minor easing of readability.
| gh pr comment ${{ github.event.pull_request.number }} --repo ${{ github.event.repository.full_name }} --body-file - <<COMMENT | ||
| :warning: Are you a trainee? It looks like you might be trying to submit an assignment. | ||
|
|
||
| If so, you are incorrectly creating a pull request to the wrong repo. Please follow these [step by step instructions](https://github.com/HackYourFuture-CPH/hyf-assignment-template?tab=readme-ov-file#2-submission-process), and remember to close this PR. |
There was a problem hiding this comment.
Every time I read this, I stumble at the clause containing two negative words: both "incorrectly" and "wrong". I wonder if we can find a clearer wording?
shpomp
left a comment
There was a problem hiding this comment.
Looks great!
I am only wondering why you would not close the PR @adamblanchard?
The way I see it is that the end result is the same either way, but force closing it rips the plaster and does not require extra step from the trainee.
I worry that leaving it be just calls for the PR to be left hanging there forever.
Although we can observe the workflow running live and maybe it will prove me wrong :)
Context: Slack discussion here
The idea is to create some kind of automation to help guide trainees who accidentally make a PR to the parent repo, instead of their own fork. This removes the need for a mentor or staff member to manually comment, and gives the trainees a chance to fix the issue on their own.
Notes and assumptions:
I tried to create a check to see if the author was in the "curriculum crew" group or in the hyf org. Unfortunately, that appeared to need greater permissions for forks to be able to read our org info. I just stopped at that point, considering I believe the check below is sufficient enough for now.
What i need a review for: