From 163edba4015947670d934ad1590dad1fb86f1104 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 10 Mar 2022 14:25:25 +0000 Subject: [PATCH] gitsrht-update-hook: include branch name in job tags This allows having a per-branch filter for build jobs. Use-cases include a build badge which only displays status for the default branch, or a getting the latest build artifacts only for the default branch. --- gitsrht-update-hook/post-update.go | 1 + gitsrht-update-hook/submitter.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/gitsrht-update-hook/post-update.go b/gitsrht-update-hook/post-update.go index a9cd3be..ef2e992 100644 --- a/gitsrht-update-hook/post-update.go +++ b/gitsrht-update-hook/post-update.go @@ -320,6 +320,7 @@ func postUpdate() { RepoName: dbinfo.RepoName, Repository: repo, Visibility: dbinfo.Visibility, + Ref: refname, } results, err := SubmitBuild(submitter) if err != nil { diff --git a/gitsrht-update-hook/submitter.go b/gitsrht-update-hook/submitter.go index bbce5f8..075b9a5 100644 --- a/gitsrht-update-hook/submitter.go +++ b/gitsrht-update-hook/submitter.go @@ -67,6 +67,8 @@ type BuildSubmitter interface { GetRepoName() string // Get the name of the repository owner GetOwnerName() string + // Get the job tags to use for this commit + GetJobTags() []string } // SQL notes @@ -86,6 +88,7 @@ type GitBuildSubmitter struct { RepoName string Repository *git.Repository Visibility string + Ref string } func (submitter GitBuildSubmitter) FindManifests() (map[string]string, error) { @@ -231,6 +234,14 @@ func (submitter GitBuildSubmitter) GetCommitNote() string { commitUrl, submitter.Commit.Author.Email) } +func (submitter GitBuildSubmitter) GetJobTags() []string { + tags := []string{submitter.GetRepoName(), "commits"} + if strings.HasPrefix(submitter.Ref, "refs/heads/") { + tags = append(tags, strings.TrimPrefix(submitter.Ref, "refs/heads/")) + } + return tags +} + func (submitter GitBuildSubmitter) GetCloneUrl() string { if submitter.Visibility == "PRIVATE" { origin := strings.ReplaceAll(submitter.GitOrigin, "http://", "") @@ -329,7 +340,7 @@ func SubmitBuild(submitter BuildSubmitter) ([]BuildSubmission, error) { Tags []string `json:"tags"` }{ Manifest: yaml, - Tags: []string{submitter.GetRepoName(), "commits", name}, + Tags: append(submitter.GetJobTags(), name), Note: submitter.GetCommitNote(), } bodyBytes, err := json.Marshal(&submission)