Skip to content

Commit

Permalink
Merge pull request #518 from MartinBasti/no-auth-for-nothing
Browse files Browse the repository at this point in the history
fix(STONEINTG-751): don't auth when there is nothing to report
  • Loading branch information
MartinBasti authored Jan 23, 2024
2 parents 883f356 + ce6bb24 commit ba041b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions status/reporters.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,13 @@ func (r *GitHubReporter) ReportStatusForSnapshot(k8sClient client.Client, ctx co
return err
}

if len(statuses.GetStatuses()) == 0 {
// no tests to report, skip
logger.Info("No test result to report to GitHub, skipping",
"snapshot.Namespace", snapshot.Namespace, "snapshot.Name", snapshot.Name)
return nil
}

labels := snapshot.GetLabels()

owner, found := labels[gitops.PipelineAsCodeURLOrgLabel]
Expand Down
7 changes: 7 additions & 0 deletions status/reporters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ var _ = Describe("GitHubReporter", func() {

It("doesn't report status when the credentials are invalid/missing", func() {
// Invalid installation ID value
hasSnapshot.Annotations["test.appstudio.openshift.io/status"] = "[{\"scenario\":\"scenario1\",\"status\":\"Pending\",\"lastUpdateTime\":\"2023-07-26T16:57:49+02:00\",\"details\":\"pending\"}]"
hasSnapshot.Annotations["pac.test.appstudio.openshift.io/installation-id"] = "bad-installation-id"
err := reporter.ReportStatusForSnapshot(mockK8sClient, context.TODO(), &logger, hasSnapshot)
Expect(err).ToNot(BeNil())
Expand All @@ -552,6 +553,12 @@ var _ = Describe("GitHubReporter", func() {
Expect(err).ToNot(BeNil())
})

It("doesn't report status when there are no tests", func() {
err := reporter.ReportStatusForSnapshot(mockK8sClient, context.TODO(), &logger, hasSnapshot)
Expect(err).To(Succeed())
Expect(mockGitHubClient.UpdateCheckRunResult.cra).To(BeNil())
})

It("reports snapshot tests status via CheckRuns", func() {
// Create an pending CheckRun
hasSnapshot.Annotations["test.appstudio.openshift.io/status"] = "[{\"scenario\":\"scenario1\",\"status\":\"Pending\",\"lastUpdateTime\":\"2023-07-26T16:57:49+02:00\",\"details\":\"pending\"}]"
Expand Down

0 comments on commit ba041b4

Please sign in to comment.