mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-16 11:09:33 +02:00
a1988f6808
* Add GH issue creation + SARIF * Code cleanup * Fix fmt, add debug * Code enhancements * Fix * Added debug info * Rework UA log scan * Fix code * read UA version * Fix nil reference * Extraction * Credentials * Issue creation * Error handling * Fix issue creation * query escape * Query escape 2 * Revert * Test avoid update * HTTP client * Add support for custom TLS certs * Fix code * Fix code 2 * Fix code 3 * Disable cert check * Fix auth * Remove implicit trust * Skip verification * Fix * Fix client * Fix HTTP auth * Fix trusted certs * Trim version * Code * Add token * Added token handling to client * Fix token * Cleanup * Fix token * Token rework * Fix code * Kick out oauth client * Kick out oauth client * Transport wrapping * Token * Simplification * Refactor * Variation * Check * Fix * Debug * Switch client * Variation * Debug * Switch to cert check * Add debug * Parse self * Cleanup * Update resources/metadata/whitesourceExecuteScan.yaml * Add debug * Expose subjects * Patch * Debug * Debug2 * Debug3 * Fix logging response body * Cleanup * Cleanup * Fix request body logging * Cleanup import * Fix import cycle * Cleanup * Fix fmt * Fix NopCloser reference * Regenerate * Reintroduce * Fix test * Fix tests * Correction * Fix error * Code fix * Fix tests * Add tests * Fix code climate issues * Code climate * Code climate again * Code climate again * Fix fmt * Fix fmt 2 Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
44 lines
1.5 KiB
Go
44 lines
1.5 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
|
"github.com/SAP/jenkins-library/pkg/telemetry"
|
|
"github.com/google/go-github/v32/github"
|
|
"github.com/pkg/errors"
|
|
|
|
piperGithub "github.com/SAP/jenkins-library/pkg/github"
|
|
)
|
|
|
|
type githubIssueCommentService interface {
|
|
CreateComment(ctx context.Context, owner string, repo string, number int, comment *github.IssueComment) (*github.IssueComment, *github.Response, error)
|
|
}
|
|
|
|
func githubCommentIssue(config githubCommentIssueOptions, telemetryData *telemetry.CustomData) {
|
|
//TODO provide parameter for trusted certs
|
|
ctx, client, err := piperGithub.NewClient(config.Token, config.APIURL, "", []string{})
|
|
if err != nil {
|
|
log.Entry().WithError(err).Fatal("Failed to get GitHub client")
|
|
}
|
|
err = runGithubCommentIssue(ctx, &config, telemetryData, client.Issues)
|
|
if err != nil {
|
|
log.Entry().WithError(err).Fatal("Failed to comment on issue")
|
|
}
|
|
}
|
|
|
|
func runGithubCommentIssue(ctx context.Context, config *githubCommentIssueOptions, _ *telemetry.CustomData, ghIssueCommentService githubIssueCommentService) error {
|
|
issueComment := github.IssueComment{
|
|
Body: &config.Body,
|
|
}
|
|
|
|
newcomment, resp, err := ghIssueCommentService.CreateComment(ctx, config.Owner, config.Repository, config.Number, &issueComment)
|
|
if err != nil {
|
|
log.Entry().Errorf("GitHub response code %v", resp.Status)
|
|
return errors.Wrapf(err, "Error occurred when creating comment on issue %v", config.Number)
|
|
}
|
|
log.Entry().Debugf("New issue comment created for issue %v: %v", config.Number, newcomment)
|
|
|
|
return nil
|
|
}
|