prow/github/report/report.go
func Report(ghc GitHubClient, reportTemplate *template.Template, pj prowapi.ProwJob, validTypes []prowapi.ProwJobType) error {
	if ghc == nil {
		return fmt.Errorf("trying to report pj %s, but found empty github client", pj.ObjectMeta.Name)
	}

	if !ShouldReport(pj, validTypes) {
		return nil
	}

	refs := pj.Spec.Refs
	// we are not reporting for batch jobs, we can consider support that in the future
	if len(refs.Pulls) > 1 {
		return nil
	}

	if err := reportStatus(ghc, pj); err != nil {
		return fmt.Errorf("error setting status: %v", err)
	}

	// Report manually aborted Jenkins jobs and jobs with invalid pod specs alongside
	// test successes/failures.
	if !pj.Complete() {
		return nil
	}

	if len(refs.Pulls) == 0 {
		return nil
	}

	ics, err := ghc.ListIssueComments(refs.Org, refs.Repo, refs.Pulls[0].Number)
	if err != nil {
		return fmt.Errorf("error listing comments: %v", err)
	}
	botName, err := ghc.BotName()
	if err != nil {
		return fmt.Errorf("error getting bot name: %v", err)
	}
	deletes, entries, updateID := parseIssueComments(pj, botName, ics)
	for _, delete := range deletes {
		if err := ghc.DeleteComment(refs.Org, refs.Repo, delete); err != nil {
			return fmt.Errorf("error deleting comment: %v", err)
		}
	}
	if len(entries) > 0 {
		comment, err := createComment(reportTemplate, pj, entries)
		if err != nil {
			return fmt.Errorf("generating comment: %v", err)
		}
		if updateID == 0 {
			if err := ghc.CreateComment(refs.Org, refs.Repo, refs.Pulls[0].Number, comment); err != nil {
				return fmt.Errorf("error creating comment: %v", err)
			}
		} else {
			if err := ghc.EditComment(refs.Org, refs.Repo, updateID, comment); err != nil {
				return fmt.Errorf("error updating comment: %v", err)
			}
		}
	}
	return nil
}
func Report(ghc GitHubClient, reportTemplate *template.Template, pj prowapi.ProwJob, validTypes []prowapi.ProwJobType) error {
	if ghc == nil {
		return fmt.Errorf("trying to report pj %s, but found empty github client", pj.ObjectMeta.Name)
	}

	if !ShouldReport(pj, validTypes) {
		return nil
	}

	refs := pj.Spec.Refs
	// we are not reporting for batch jobs, we can consider support that in the future
	if len(refs.Pulls) > 1 {
		return nil
	}

	if err := reportStatus(ghc, pj); err != nil {
		return fmt.Errorf("error setting status: %v", err)
	}

	// Report manually aborted Jenkins jobs and jobs with invalid pod specs alongside
	// test successes/failures.
	if !pj.Complete() {
		return nil
	}

	if len(refs.Pulls) == 0 {
		return nil
	}

	ics, err := ghc.ListIssueComments(refs.Org, refs.Repo, refs.Pulls[0].Number)
	if err != nil {
		return fmt.Errorf("error listing comments: %v", err)
	}
	botName, err := ghc.BotName()
	if err != nil {
		return fmt.Errorf("error getting bot name: %v", err)
	}
	deletes, entries, updateID := parseIssueComments(pj, botName, ics)
	for _, delete := range deletes {
		if err := ghc.DeleteComment(refs.Org, refs.Repo, delete); err != nil {
			return fmt.Errorf("error deleting comment: %v", err)
		}
	}
	if len(entries) > 0 {
		comment, err := createComment(reportTemplate, pj, entries)
		if err != nil {
			return fmt.Errorf("generating comment: %v", err)
		}
		if updateID == 0 {
			if err := ghc.CreateComment(refs.Org, refs.Repo, refs.Pulls[0].Number, comment); err != nil {
				return fmt.Errorf("error creating comment: %v", err)
			}
		} else {
			if err := ghc.EditComment(refs.Org, refs.Repo, updateID, comment); err != nil {
				return fmt.Errorf("error updating comment: %v", err)
			}
		}
	}
	return nil
}
func Report ( ghc GitHubClient , reportTemplate * template . Template , pj prowapi . ProwJob , validTypes [ ] prowapi . ProwJobType ) error { if ghc == nil { return fmt . Errorf ( " " , pj . ObjectMeta . Name ) } if ! ShouldReport ( pj , validTypes ) { return nil } refs := pj . Spec . Refs // we are not reporting for batch jobs, we can consider support that in the future if len ( refs . Pulls ) > 1 { return nil } if err := reportStatus ( ghc , pj ) ; err != nil { return fmt . Errorf ( " " , err ) } // Report manually aborted Jenkins jobs and jobs with invalid pod specs alongside // test successes/failures. if ! pj . Complete ( ) { return nil } if len ( refs . Pulls ) == 0 { return nil } ics , err := ghc . ListIssueComments ( refs . Org , refs . Repo , refs . Pulls [ 0 ] . Number ) if err != nil { return fmt . Errorf ( " " , err ) } botName , err := ghc . BotName ( ) if err != nil { return fmt . Errorf ( " " , err ) } deletes , entries , updateID := parseIssueComments ( pj , botName , ics ) for _ , delete := range deletes { if err := ghc . DeleteComment ( refs . Org , refs . Repo , delete ) ; err != nil { return fmt . Errorf ( " " , err ) } } if len ( entries ) > 0 { comment , err := createComment ( reportTemplate , pj , entries ) if err != nil { return fmt . Errorf ( " " , err ) } if updateID == 0 { if err := ghc . CreateComment ( refs . Org , refs . Repo , refs . Pulls [ 0 ] . Number , comment ) ; err != nil { return fmt . Errorf ( " " , err ) } } else { if err := ghc . EditComment ( refs . Org , refs . Repo , updateID , comment ) ; err != nil { return fmt . Errorf ( " " , err ) } } } return nil }
// Report is creating/updating/removing reports in GitHub based on the state of
// the provided ProwJob.
Report is creating / updating / removing reports in GitHub based on the state of the provided ProwJob .