~edwargix/git.sr.ht

163edba4015947670d934ad1590dad1fb86f1104 — Simon Ser 2 years ago be6100f
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.
2 files changed, 13 insertions(+), 1 deletions(-)

M gitsrht-update-hook/post-update.go
M gitsrht-update-hook/submitter.go
M gitsrht-update-hook/post-update.go => gitsrht-update-hook/post-update.go +1 -0
@@ 320,6 320,7 @@ func postUpdate() {
				RepoName:    dbinfo.RepoName,
				Repository:  repo,
				Visibility:  dbinfo.Visibility,
				Ref:         refname,
			}
			results, err := SubmitBuild(submitter)
			if err != nil {

M gitsrht-update-hook/submitter.go => gitsrht-update-hook/submitter.go +12 -1
@@ 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)