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: support getting scm status url from tekton pipeline result #1615

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/pipelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,8 @@ spec:
```

e.g. here is [an example](../pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-multiple-copies/source.yaml#L8) which generates this [PipelineRun](../pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-multiple-copies/expected.yaml#L154)

## Override scm status url from pipeline

If a pipeline has a result named `scm-status-url` the value of that will be used as link target for the pipeline status
set in scm provider (like GitHub or GitLab) instead of the link to the pipeline dashboard.
15 changes: 11 additions & 4 deletions pkg/engines/tekton/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
)

// ConvertPipelineRun translates a PipelineRun into an ActivityRecord
func ConvertPipelineRun(pr *v1beta1.PipelineRun) *v1alpha1.ActivityRecord {
func ConvertPipelineRun(pr *v1beta1.PipelineRun) (record *v1alpha1.ActivityRecord, resultUrl string) {
if pr == nil {
return nil
return
}

record := new(v1alpha1.ActivityRecord)
record = new(v1alpha1.ActivityRecord)

record.Name = pr.Name

Expand All @@ -41,6 +41,13 @@ func ConvertPipelineRun(pr *v1beta1.PipelineRun) *v1alpha1.ActivityRecord {

record.Status = convertTektonStatus(cond, record.StartTime, record.CompletionTime)

for i := range pr.Status.PipelineResults {
res := pr.Status.PipelineResults[i]
if res.Name == tektonResultScmStatusUrl {
resultUrl = res.Value.StringVal
}
}

for _, taskName := range sets.StringKeySet(pr.Status.TaskRuns).List() {
task := pr.Status.TaskRuns[taskName]
cleanedUpTaskName := strings.TrimPrefix(taskName[:len(taskName)-6], pr.Name+"-")
Expand Down Expand Up @@ -80,7 +87,7 @@ func ConvertPipelineRun(pr *v1beta1.PipelineRun) *v1alpha1.ActivityRecord {
}
// log URL is definitely gonna wait

return record
return
}

func convertTektonStatus(cond *apis.Condition, start, finished *metav1.Time) v1alpha1.PipelineState {
Expand Down
2 changes: 1 addition & 1 deletion pkg/engines/tekton/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestConvertPipelineRun(t *testing.T) {
testDir := filepath.Join("test_data", "activity", tc.name)
pr := loadPipelineRun(t, testDir)

converted := tekton.ConvertPipelineRun(pr)
converted, _ := tekton.ConvertPipelineRun(pr)

expected := loadRecord(t, testDir)

Expand Down
4 changes: 2 additions & 2 deletions pkg/engines/tekton/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ func (r *LighthouseJobReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}

f := func(job *lighthousev1alpha1.LighthouseJob) error {
if r.dashboardURL != "" {
job.Status.Activity, job.Status.ReportURL = ConvertPipelineRun(&pipelineRun)
if job.Status.ReportURL == "" && r.dashboardURL != "" {
job.Status.ReportURL = r.getPipelingetPipelineTargetURLeTargetURL(pipelineRun)
}
job.Status.Activity = ConvertPipelineRun(&pipelineRun)
if err := r.client.Status().Update(ctx, job); err != nil {
return errors.Wrapf(err, "failed to update LighthouseJob status")
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/engines/tekton/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import (
)

const (
controllerName = "tekton-controller"
gitCloneCatalogTaskName = "git-clone"
gitCloneURLParam = "url"
gitCloneRevisionParam = "revision"
gitMergeCatalogTaskName = "git-batch-merge"
gitMergeBatchRefsParam = "batchedRefs"
controllerName = "tekton-controller"
gitCloneCatalogTaskName = "git-clone"
gitCloneURLParam = "url"
gitCloneRevisionParam = "revision"
gitMergeCatalogTaskName = "git-batch-merge"
gitMergeBatchRefsParam = "batchedRefs"
tektonResultScmStatusUrl = "scm-status-url"
)

type buildIDGenerator interface {
Expand Down
Loading