Skip to content

Commit

Permalink
Merge branch 'main' into enhance/scheduledBuildBranches
Browse files Browse the repository at this point in the history
  • Loading branch information
KellyMerrick authored Aug 22, 2023
2 parents 03f8c13 + ee0d2a0 commit c0d16a4
Show file tree
Hide file tree
Showing 111 changed files with 602 additions and 327 deletions.
5 changes: 4 additions & 1 deletion api/admin/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ import (
func UpdateRepo(c *gin.Context) {
logrus.Info("Admin: updating repo in database")

// capture middleware values
ctx := c.Request.Context()

// capture body from API request
input := new(library.Repo)

Expand All @@ -66,7 +69,7 @@ func UpdateRepo(c *gin.Context) {
}

// send API call to update the repo
r, err := database.FromContext(c).UpdateRepo(input)
r, err := database.FromContext(c).UpdateRepo(ctx, input)
if err != nil {
retErr := fmt.Errorf("unable to update repo %d: %w", input.GetID(), err)

Expand Down
4 changes: 2 additions & 2 deletions api/admin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func UpdateService(c *gin.Context) {
}

// send API call to update the service
err = database.FromContext(c).UpdateService(input)
s, err := database.FromContext(c).UpdateService(input)
if err != nil {
retErr := fmt.Errorf("unable to update service %d: %w", input.GetID(), err)

Expand All @@ -76,5 +76,5 @@ func UpdateService(c *gin.Context) {
return
}

c.JSON(http.StatusOK, input)
c.JSON(http.StatusOK, s)
}
2 changes: 1 addition & 1 deletion api/build/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func CancelBuild(c *gin.Context) {
if service.GetStatus() == constants.StatusRunning || service.GetStatus() == constants.StatusPending {
service.SetStatus(constants.StatusCanceled)

err = database.FromContext(c).UpdateService(service)
_, err = database.FromContext(c).UpdateService(service)
if err != nil {
retErr := fmt.Errorf("unable to update service %s for build %s: %w",
service.GetName(),
Expand Down
2 changes: 1 addition & 1 deletion api/build/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func CleanBuild(ctx context.Context, database database.Interface, b *library.Bui
s.SetFinished(time.Now().UTC().Unix())

// send API call to update the service
err := database.UpdateService(s)
_, err := database.UpdateService(s)
if err != nil {
logrus.Errorf("unable to kill service %s for build %d: %v", s.GetName(), b.GetNumber(), err)
}
Expand Down
6 changes: 3 additions & 3 deletions api/build/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func CreateBuild(c *gin.Context) {
)

// send API call to attempt to capture the pipeline
pipeline, err = database.FromContext(c).GetPipelineForRepo(input.GetCommit(), r)
pipeline, err = database.FromContext(c).GetPipelineForRepo(ctx, input.GetCommit(), r)
if err != nil { // assume the pipeline doesn't exist in the database yet
// send API call to capture the pipeline configuration file
config, err = scm.FromContext(c).ConfigBackoff(u, r, input.GetCommit())
Expand Down Expand Up @@ -309,7 +309,7 @@ func CreateBuild(c *gin.Context) {
pipeline.SetRef(input.GetRef())

// send API call to create the pipeline
pipeline, err = database.FromContext(c).CreatePipeline(pipeline)
pipeline, err = database.FromContext(c).CreatePipeline(ctx, pipeline)
if err != nil {
retErr := fmt.Errorf("unable to create new build: failed to create pipeline for %s: %w", r.GetFullName(), err)

Expand All @@ -330,7 +330,7 @@ func CreateBuild(c *gin.Context) {
}

// send API call to update repo for ensuring counter is incremented
r, err = database.FromContext(c).UpdateRepo(r)
r, err = database.FromContext(c).UpdateRepo(ctx, r)
if err != nil {
retErr := fmt.Errorf("unable to create new build: failed to update repo %s: %w", r.GetFullName(), err)

Expand Down
2 changes: 1 addition & 1 deletion api/build/get_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func GetBuildByID(c *gin.Context) {
}

// Get repo from database using repo ID field from build
r, err = database.FromContext(c).GetRepo(b.GetRepoID())
r, err = database.FromContext(c).GetRepo(ctx, b.GetRepoID())
if err != nil {
retErr := fmt.Errorf("unable to get repo: %w", err)

Expand Down
6 changes: 3 additions & 3 deletions api/build/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func RestartBuild(c *gin.Context) {
)

// send API call to attempt to capture the pipeline
pipeline, err = database.FromContext(c).GetPipelineForRepo(b.GetCommit(), r)
pipeline, err = database.FromContext(c).GetPipelineForRepo(ctx, b.GetCommit(), r)
if err != nil { // assume the pipeline doesn't exist in the database yet (before pipeline support was added)
// send API call to capture the pipeline configuration file
config, err = scm.FromContext(c).ConfigBackoff(u, r, b.GetCommit())
Expand Down Expand Up @@ -300,7 +300,7 @@ func RestartBuild(c *gin.Context) {
pipeline.SetRef(b.GetRef())

// send API call to create the pipeline
pipeline, err = database.FromContext(c).CreatePipeline(pipeline)
pipeline, err = database.FromContext(c).CreatePipeline(ctx, pipeline)
if err != nil {
retErr := fmt.Errorf("unable to create pipeline for %s: %w", r.GetFullName(), err)

Expand All @@ -321,7 +321,7 @@ func RestartBuild(c *gin.Context) {
}

// send API call to update repo for ensuring counter is incremented
r, err = database.FromContext(c).UpdateRepo(r)
r, err = database.FromContext(c).UpdateRepo(ctx, r)
if err != nil {
retErr := fmt.Errorf("unable to restart build: failed to update repo %s: %w", r.GetFullName(), err)
util.HandleError(c, http.StatusBadRequest, retErr)
Expand Down
2 changes: 1 addition & 1 deletion api/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func recordGauges(c *gin.Context) {
// repo_count
if q.RepoCount {
// send API call to capture the total number of repos
r, err := database.FromContext(c).CountRepos()
r, err := database.FromContext(c).CountRepos(ctx)
if err != nil {
logrus.Errorf("unable to get count of all repos: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion api/pipeline/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func CreatePipeline(c *gin.Context) {
o := org.Retrieve(c)
r := repo.Retrieve(c)
u := user.Retrieve(c)
ctx := c.Request.Context()

// update engine logger with API metadata
//
Expand Down Expand Up @@ -98,7 +99,7 @@ func CreatePipeline(c *gin.Context) {
input.SetRepoID(r.GetID())

// send API call to create the pipeline
p, err := database.FromContext(c).CreatePipeline(input)
p, err := database.FromContext(c).CreatePipeline(ctx, input)
if err != nil {
retErr := fmt.Errorf("unable to create pipeline %s/%s: %w", r.GetFullName(), input.GetCommit(), err)

Expand Down
3 changes: 2 additions & 1 deletion api/pipeline/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func DeletePipeline(c *gin.Context) {
p := pipeline.Retrieve(c)
r := repo.Retrieve(c)
u := user.Retrieve(c)
ctx := c.Request.Context()

entry := fmt.Sprintf("%s/%s", r.GetFullName(), p.GetCommit())

Expand All @@ -79,7 +80,7 @@ func DeletePipeline(c *gin.Context) {
}).Infof("deleting pipeline %s", entry)

// send API call to remove the build
err := database.FromContext(c).DeletePipeline(p)
err := database.FromContext(c).DeletePipeline(ctx, p)
if err != nil {
retErr := fmt.Errorf("unable to delete pipeline %s: %w", entry, err)

Expand Down
3 changes: 2 additions & 1 deletion api/pipeline/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func ListPipelines(c *gin.Context) {
o := org.Retrieve(c)
r := repo.Retrieve(c)
u := user.Retrieve(c)
ctx := c.Request.Context()

// update engine logger with API metadata
//
Expand Down Expand Up @@ -117,7 +118,7 @@ func ListPipelines(c *gin.Context) {
//nolint:gomnd // ignore magic number
perPage = util.MaxInt(1, util.MinInt(100, perPage))

p, t, err := database.FromContext(c).ListPipelinesForRepo(r, page, perPage)
p, t, err := database.FromContext(c).ListPipelinesForRepo(ctx, r, page, perPage)
if err != nil {
retErr := fmt.Errorf("unable to list pipelines for repo %s: %w", r.GetFullName(), err)

Expand Down
3 changes: 2 additions & 1 deletion api/pipeline/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func UpdatePipeline(c *gin.Context) {
p := pipeline.Retrieve(c)
r := repo.Retrieve(c)
u := user.Retrieve(c)
ctx := c.Request.Context()

entry := fmt.Sprintf("%s/%s", r.GetFullName(), p.GetCommit())

Expand Down Expand Up @@ -170,7 +171,7 @@ func UpdatePipeline(c *gin.Context) {
}

// send API call to update the pipeline
p, err = database.FromContext(c).UpdatePipeline(p)
p, err = database.FromContext(c).UpdatePipeline(ctx, p)
if err != nil {
retErr := fmt.Errorf("unable to update pipeline %s: %w", entry, err)

Expand Down
3 changes: 2 additions & 1 deletion api/repo/chown.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func ChownRepo(c *gin.Context) {
o := org.Retrieve(c)
r := repo.Retrieve(c)
u := user.Retrieve(c)
ctx := c.Request.Context()

// update engine logger with API metadata
//
Expand All @@ -68,7 +69,7 @@ func ChownRepo(c *gin.Context) {
r.SetUserID(u.GetID())

// send API call to update the repo
_, err := database.FromContext(c).UpdateRepo(r)
_, err := database.FromContext(c).UpdateRepo(ctx, r)
if err != nil {
retErr := fmt.Errorf("unable to change owner of repo %s to %s: %w", r.GetFullName(), u.GetName(), err)

Expand Down
7 changes: 4 additions & 3 deletions api/repo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func CreateRepo(c *gin.Context) {
defaultTimeout := c.Value("defaultTimeout").(int64)
maxBuildLimit := c.Value("maxBuildLimit").(int64)
defaultRepoEvents := c.Value("defaultRepoEvents").([]string)
ctx := c.Request.Context()

// capture body from API request
input := new(library.Repo)
Expand Down Expand Up @@ -221,7 +222,7 @@ func CreateRepo(c *gin.Context) {
}

// send API call to capture the repo from the database
dbRepo, err := database.FromContext(c).GetRepoForOrg(r.GetOrg(), r.GetName())
dbRepo, err := database.FromContext(c).GetRepoForOrg(ctx, r.GetOrg(), r.GetName())
if err == nil && dbRepo.GetActive() {
retErr := fmt.Errorf("unable to activate repo: %s is already active", r.GetFullName())

Expand Down Expand Up @@ -283,7 +284,7 @@ func CreateRepo(c *gin.Context) {
dbRepo.SetActive(true)

// send API call to update the repo
r, err = database.FromContext(c).UpdateRepo(dbRepo)
r, err = database.FromContext(c).UpdateRepo(ctx, dbRepo)
if err != nil {
retErr := fmt.Errorf("unable to set repo %s to active: %w", dbRepo.GetFullName(), err)

Expand All @@ -293,7 +294,7 @@ func CreateRepo(c *gin.Context) {
}
} else {
// send API call to create the repo
r, err = database.FromContext(c).CreateRepo(r)
r, err = database.FromContext(c).CreateRepo(ctx, r)
if err != nil {
retErr := fmt.Errorf("unable to create new repo %s: %w", r.GetFullName(), err)

Expand Down
3 changes: 2 additions & 1 deletion api/repo/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func DeleteRepo(c *gin.Context) {
o := org.Retrieve(c)
r := repo.Retrieve(c)
u := user.Retrieve(c)
ctx := c.Request.Context()

// update engine logger with API metadata
//
Expand Down Expand Up @@ -88,7 +89,7 @@ func DeleteRepo(c *gin.Context) {
// Mark the repo as inactive
r.SetActive(false)

_, err = database.FromContext(c).UpdateRepo(r)
_, err = database.FromContext(c).UpdateRepo(ctx, r)
if err != nil {
retErr := fmt.Errorf("unable to set repo %s to inactive: %w", r.GetFullName(), err)

Expand Down
3 changes: 2 additions & 1 deletion api/repo/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import (
func ListRepos(c *gin.Context) {
// capture middleware values
u := user.Retrieve(c)
ctx := c.Request.Context()

// update engine logger with API metadata
//
Expand Down Expand Up @@ -108,7 +109,7 @@ func ListRepos(c *gin.Context) {
}

// send API call to capture the list of repos for the user
r, t, err := database.FromContext(c).ListReposForUser(u, sortBy, filters, page, perPage)
r, t, err := database.FromContext(c).ListReposForUser(ctx, u, sortBy, filters, page, perPage)
if err != nil {
retErr := fmt.Errorf("unable to get repos for user %s: %w", u.GetName(), err)

Expand Down
3 changes: 2 additions & 1 deletion api/repo/list_org.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func ListReposForOrg(c *gin.Context) {
// capture middleware values
o := org.Retrieve(c)
u := user.Retrieve(c)
ctx := c.Request.Context()

// update engine logger with API metadata
//
Expand Down Expand Up @@ -141,7 +142,7 @@ func ListReposForOrg(c *gin.Context) {
}

// send API call to capture the list of repos for the org
r, t, err := database.FromContext(c).ListReposForOrg(o, sortBy, filters, page, perPage)
r, t, err := database.FromContext(c).ListReposForOrg(ctx, o, sortBy, filters, page, perPage)
if err != nil {
retErr := fmt.Errorf("unable to get repos for org %s: %w", o, err)

Expand Down
3 changes: 2 additions & 1 deletion api/repo/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func RepairRepo(c *gin.Context) {
o := org.Retrieve(c)
r := repo.Retrieve(c)
u := user.Retrieve(c)
ctx := c.Request.Context()

// update engine logger with API metadata
//
Expand Down Expand Up @@ -122,7 +123,7 @@ func RepairRepo(c *gin.Context) {
r.SetActive(true)

// send API call to update the repo
_, err := database.FromContext(c).UpdateRepo(r)
_, err := database.FromContext(c).UpdateRepo(ctx, r)
if err != nil {
retErr := fmt.Errorf("unable to set repo %s to active: %w", r.GetFullName(), err)

Expand Down
3 changes: 2 additions & 1 deletion api/repo/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func UpdateRepo(c *gin.Context) {
r := repo.Retrieve(c)
u := user.Retrieve(c)
maxBuildLimit := c.Value("maxBuildLimit").(int64)
ctx := c.Request.Context()

// update engine logger with API metadata
//
Expand Down Expand Up @@ -295,7 +296,7 @@ func UpdateRepo(c *gin.Context) {
}

// send API call to update the repo
r, err = database.FromContext(c).UpdateRepo(r)
r, err = database.FromContext(c).UpdateRepo(ctx, r)
if err != nil {
retErr := fmt.Errorf("unable to update repo %s: %w", r.GetFullName(), err)

Expand Down
3 changes: 2 additions & 1 deletion api/scm/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func SyncRepo(c *gin.Context) {
o := org.Retrieve(c)
r := repo.Retrieve(c)
u := user.Retrieve(c)
ctx := c.Request.Context()

// update engine logger with API metadata
//
Expand All @@ -80,7 +81,7 @@ func SyncRepo(c *gin.Context) {
r.SetActive(false)

// update repo in database
_, err := database.FromContext(c).UpdateRepo(r)
_, err := database.FromContext(c).UpdateRepo(ctx, r)
if err != nil {
retErr := fmt.Errorf("unable to update repo for org %s: %w", o, err)

Expand Down
7 changes: 4 additions & 3 deletions api/scm/sync_org.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func SyncReposForOrg(c *gin.Context) {
// capture middleware values
o := org.Retrieve(c)
u := user.Retrieve(c)
ctx := c.Request.Context()

// update engine logger with API metadata
//
Expand Down Expand Up @@ -79,7 +80,7 @@ func SyncReposForOrg(c *gin.Context) {
}

// send API call to capture the total number of repos for the org
t, err := database.FromContext(c).CountReposForOrg(o, map[string]interface{}{})
t, err := database.FromContext(c).CountReposForOrg(ctx, o, map[string]interface{}{})
if err != nil {
retErr := fmt.Errorf("unable to get repo count for org %s: %w", o, err)

Expand All @@ -92,7 +93,7 @@ func SyncReposForOrg(c *gin.Context) {
page := 0
// capture all repos belonging to a certain org in database
for orgRepos := int64(0); orgRepos < t; orgRepos += 100 {
r, _, err := database.FromContext(c).ListReposForOrg(o, "name", map[string]interface{}{}, page, 100)
r, _, err := database.FromContext(c).ListReposForOrg(ctx, o, "name", map[string]interface{}{}, page, 100)
if err != nil {
retErr := fmt.Errorf("unable to get repo count for org %s: %w", o, err)

Expand All @@ -113,7 +114,7 @@ func SyncReposForOrg(c *gin.Context) {
if err != nil {
repo.SetActive(false)

_, err := database.FromContext(c).UpdateRepo(repo)
_, err := database.FromContext(c).UpdateRepo(ctx, repo)
if err != nil {
retErr := fmt.Errorf("unable to update repo for org %s: %w", o, err)

Expand Down
5 changes: 1 addition & 4 deletions api/service/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func CreateService(c *gin.Context) {
}

// send API call to create the service
err = database.FromContext(c).CreateService(input)
s, err := database.FromContext(c).CreateService(input)
if err != nil {
retErr := fmt.Errorf("unable to create service for build %s: %w", entry, err)

Expand All @@ -121,8 +121,5 @@ func CreateService(c *gin.Context) {
return
}

// send API call to capture the created service
s, _ := database.FromContext(c).GetServiceForBuild(b, input.GetNumber())

c.JSON(http.StatusCreated, s)
}
Loading

0 comments on commit c0d16a4

Please sign in to comment.