1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/cmd/githubCreateIssue.go
Oliver Nocon 7de42230e0
add step to create a GitHub issue (#2481)
* add step to create a GirHub issue

* add groovy library step

* Update githubcreateissue.yaml

Co-authored-by: Sven Merk <33895725+nevskrem@users.noreply.github.com>
2020-12-21 17:13:16 +01:00

44 lines
1.4 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 githubCreateIssueService interface {
Create(ctx context.Context, owner string, repo string, issue *github.IssueRequest) (*github.Issue, *github.Response, error)
}
func githubCreateIssue(config githubCreateIssueOptions, telemetryData *telemetry.CustomData) {
ctx, client, err := piperGithub.NewClient(config.Token, config.APIURL, "")
if err != nil {
log.Entry().WithError(err).Fatal("Failed to get GitHub client")
}
err = runGithubCreateIssue(ctx, &config, telemetryData, client.Issues)
if err != nil {
log.Entry().WithError(err).Fatal("Failed to comment on issue")
}
}
func runGithubCreateIssue(ctx context.Context, config *githubCreateIssueOptions, _ *telemetry.CustomData, ghCreateIssueService githubCreateIssueService) error {
issue := github.IssueRequest{
Body: &config.Body,
Title: &config.Title,
}
newIssue, resp, err := ghCreateIssueService.Create(ctx, config.Owner, config.Repository, &issue)
if err != nil {
log.Entry().Errorf("GitHub response code %v", resp.Status)
return errors.Wrap(err, "Error occurred when creating issue")
}
log.Entry().Debugf("New issue created: %v", newIssue)
return nil
}