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(webhook)!: support build approval based on repository settings #1016

Merged
merged 14 commits into from
Dec 8, 2023

Conversation

ecrupper
Copy link
Contributor

This is the server-side implementation for approving builds, specifically from fork repos during PR builds.

A couple small refactors that made this possible:

  • PublishToQueue now takes the route as a parameter rather than determining it. This was done in order to avoid unmarshaling the pipeline object when approved. We're able to do this by preemptively setting the build.Host to the specified route rather than waiting for a worker to pick it up.
  • RepoAccess accepts a user name rather than an entire user object since that's all we need + adds ability to check for access of sender without creating a fake user object and populating the name
  • executors.Establish() has an additional check on build status since host is now being set as the route while the build is pending / pending approval.

The main idea of the implementation is to separate the publishing of the build executable from the publishing to the queue. If the build is clear to run, the PostWebhook handler will take care of both. However, if it is not clear to run, then the new ApproveBuild handler will handle queue publishing while the PostWebhook handler just generates and publishes the executable.

Lastly, the status report to the SCM for builds pending approval has been adjusted to describe the situation, making the experience more understandable for users having their builds gated.

@ecrupper ecrupper requested a review from a team as a code owner November 28, 2023 17:30
api/build/approve.go Outdated Show resolved Hide resolved
scm/github/access.go Show resolved Hide resolved
scm/github/repo.go Outdated Show resolved Hide resolved
Copy link

codecov bot commented Nov 28, 2023

Codecov Report

Merging #1016 (cbef404) into main (5e1a7d3) will decrease coverage by 0.48%.
The diff coverage is 5.92%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1016      +/-   ##
==========================================
- Coverage   68.36%   67.89%   -0.48%     
==========================================
  Files         317      318       +1     
  Lines       13641    13738      +97     
==========================================
+ Hits         9326     9327       +1     
- Misses       3848     3944      +96     
  Partials      467      467              
Files Coverage Δ
scm/github/webhook.go 85.60% <100.00%> (+0.03%) ⬆️
api/build/get_id.go 0.00% <0.00%> (ø)
api/build/publish.go 0.00% <0.00%> (ø)
api/build/cancel.go 0.00% <0.00%> (ø)
scm/github/access.go 82.17% <57.14%> (ø)
scm/github/repo.go 76.56% <0.00%> (-0.54%) ⬇️
router/middleware/executors/executors.go 2.46% <0.00%> (-0.07%) ⬇️
router/middleware/perm/perm.go 59.12% <42.85%> (ø)
api/build/create.go 0.00% <0.00%> (ø)
api/build/executable.go 0.00% <0.00%> (ø)
... and 2 more

scm/github/repo.go Outdated Show resolved Hide resolved
KellyMerrick
KellyMerrick previously approved these changes Nov 29, 2023
Copy link
Contributor

@KellyMerrick KellyMerrick left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@KellyMerrick KellyMerrick left a comment

Choose a reason for hiding this comment

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

lgtm

@ecrupper ecrupper merged commit 5fc317f into main Dec 8, 2023
10 of 12 checks passed
@ecrupper ecrupper deleted the feat/fork-pr-approve-build branch December 8, 2023 19:34
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.

3 participants