-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(repo)!: add pending approval timeout (#1227)
* init commit * feat(repo): add pending approval timeout * fix test * remove dead code --------- Co-authored-by: David May <[email protected]>
- Loading branch information
1 parent
ada42d5
commit 70ca430
Showing
29 changed files
with
1,100 additions
and
651 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package build | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/go-vela/server/api/types" | ||
"github.com/go-vela/server/constants" | ||
"github.com/go-vela/server/database" | ||
"github.com/go-vela/server/scm" | ||
) | ||
|
||
// GatekeepBuild is a helper function that will set the status of a build to 'pending approval' and | ||
// send a status update to the SCM. | ||
func GatekeepBuild(c *gin.Context, b *types.Build, r *types.Repo) error { | ||
l := c.MustGet("logger").(*logrus.Entry) | ||
|
||
l = l.WithFields(logrus.Fields{ | ||
"org": r.GetOrg(), | ||
"repo": r.GetName(), | ||
"repo_id": r.GetID(), | ||
"build": b.GetNumber(), | ||
"build_id": b.GetID(), | ||
}) | ||
|
||
l.Debug("fork PR build waiting for approval") | ||
|
||
b.SetStatus(constants.StatusPendingApproval) | ||
|
||
_, err := database.FromContext(c).UpdateBuild(c, b) | ||
if err != nil { | ||
return fmt.Errorf("unable to update build for %s/%d: %w", r.GetFullName(), b.GetNumber(), err) | ||
} | ||
|
||
l.Info("build updated") | ||
|
||
// update the build components to pending approval status | ||
err = UpdateComponentStatuses(c, b, constants.StatusPendingApproval) | ||
if err != nil { | ||
return fmt.Errorf("unable to update build components for %s/%d: %w", r.GetFullName(), b.GetNumber(), err) | ||
} | ||
|
||
// send API call to set the status on the commit | ||
err = scm.FromContext(c).Status(c, r.GetOwner(), b, r.GetOrg(), r.GetName()) | ||
if err != nil { | ||
l.Errorf("unable to set commit status for %s/%d: %v", r.GetFullName(), b.GetNumber(), err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.