Skip to content

Commit

Permalink
Merge pull request #1612 from JordanGoasdoue/feat-skip-running-status
Browse files Browse the repository at this point in the history
feat: skip running status (running/pending) if last state
  • Loading branch information
jenkins-x-bot authored Jul 2, 2024
2 parents 1d8c55f + 2d69553 commit c699cbe
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ Trigger specifies a configuration for a single trigger.<br /><br />The configura
| `elide_skipped_contexts` | bool | No | ElideSkippedContexts makes trigger not post "Skipped" contexts for jobs<br />that could run but do not run. |
| `skip_draft_pr` | bool | No | SkipDraftPR when enabled, skips triggering pipelines for draft PRs<br />unless /ok-to-test is added. |
| `skip_report_comment` | bool | No | SkipReportComment when enabled, skips report comments in the SCM provider based on the state of<br />the LighthouseJobs. |
| `skip_report_running_status` | bool | No | SkipReportRunningStatus when enabled, skips report status in the SCM provider based on the current and last state of the LighthouseJobs. |

## Welcome

Expand Down
1 change: 1 addition & 0 deletions docs/plugins/Plugins config.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ Trigger specifies a configuration for a single trigger.<br /><br />The configura
| ElideSkippedContexts | `elide_skipped_contexts` | bool | No | ElideSkippedContexts makes trigger not post "Skipped" contexts for jobs<br />that could run but do not run. |
| SkipDraftPR | `skip_draft_pr` | bool | No | SkipDraftPR when enabled, skips triggering pipelines for draft PRs<br />unless /ok-to-test is added. |
| SkipReportComment | `skip_report_comment` | bool | No | SkipReportComment when enabled, skips report comments in the SCM provider based on the state of<br />the LighthouseJobs. |
| SkipReportRunningStatus | `skip_report_running_status` | bool | No | SkipReportRunningStatus when enabled, skips report status in the SCM provider based on the current and last state of<br />the LighthouseJobs. |

## Welcome

Expand Down
14 changes: 12 additions & 2 deletions pkg/foghorn/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ func (r *LighthouseJobReconciler) reportStatus(activity *lighthousev1alpha1.Acti
repo := activity.Repo
gitURL := activity.GitURL
activityStatus := activity.Status
statusInfo := toScmStatusDescriptionRunningStages(activity, util.GitKind(r.jobConfig.Config))
skipReportRunningStatus := r.pluginConfig.Config().TriggerFor(owner, repo).SkipReportRunningStatus
statusInfo := toScmStatusDescriptionRunningStages(activity, util.GitKind(r.jobConfig.Config), skipReportRunningStatus)

fields := map[string]interface{}{
"name": activity.Name,
Expand Down Expand Up @@ -224,6 +225,11 @@ func (r *LighthouseJobReconciler) reportStatus(activity *lighthousev1alpha1.Acti
// already completed - avoid reporting again if a promotion happens after a PR has merged and the pipeline updates status
case scm.StateFailure, scm.StateError, scm.StateSuccess, scm.StateCanceled:
return
// already in running/pending state - avoid reporting again if we are still in these status
case scm.StatePending, scm.StateRunning:
if skipReportRunningStatus && (statusInfo.scmStatus == scm.StatePending || statusInfo.scmStatus == scm.StateRunning) {
return
}
}

r.logger.WithFields(fields).Warnf("last report: %s, current: %s, last desc: %s, current: %s", j.Status.LastReportState, statusInfo.scmStatus.String(),
Expand Down Expand Up @@ -283,7 +289,7 @@ type reportStatusInfo struct {
runningStages string
}

func toScmStatusDescriptionRunningStages(activity *lighthousev1alpha1.ActivityRecord, gitKind string) reportStatusInfo {
func toScmStatusDescriptionRunningStages(activity *lighthousev1alpha1.ActivityRecord, gitKind string, skipReportRunningStatus bool) reportStatusInfo {
info := reportStatusInfo{
description: "",
runningStages: "",
Expand All @@ -307,6 +313,10 @@ func toScmStatusDescriptionRunningStages(activity *lighthousev1alpha1.ActivityRe
info.description = "Pipeline in unknown state"
}

if skipReportRunningStatus {
return info
}

runningStages := activity.RunningStages()
// GitLab does not currently support updating description without changing state, so we need simple descriptions there.
// TODO: link to GitLab issue (apb)
Expand Down
3 changes: 3 additions & 0 deletions pkg/plugins/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ type Trigger struct {
// SkipReportComment when enabled, skips report comments in the SCM provider based on the state of
// the LighthouseJobs.
SkipReportComment bool `json:"skip_report_comment,omitempty"`
// SkipReportRunningStatus when enabled, skips report status in the SCM provider
// based on the current and last state of the LighthouseJobs.
SkipReportRunningStatus bool `json:"skip_report_running_status,omitempty"`
}

// Milestone contains the configuration options for the milestone and
Expand Down

0 comments on commit c699cbe

Please sign in to comment.