diff --git a/internal/pkg/githubapi/.tmpMJcSWN b/internal/pkg/githubapi/.tmpMJcSWN deleted file mode 100644 index a304e05..0000000 --- a/internal/pkg/githubapi/.tmpMJcSWN +++ /dev/null @@ -1,93 +0,0 @@ -package githubapi - -import ( - "context" - "fmt" - "path" - "strings" - - "github.com/google/go-github/v48/github" - log "github.com/sirupsen/logrus" - prom "github.com/wayfair-incubator/telefonistka/internal/pkg/prometheus" -) - -type GhPrClientDetails struct { - Ghclient *github.Client - // This whole struct describe the metadata of the PR, so it makes sense to share the context with everything to generate HTTP calls related to that PR, right? - Ctx context.Context //nolint:containedctx - DefaultBranch string - Owner string - Repo string - PrAuthor string - PrNumber int - PrSHA string - Ref string - PrLogger *log.Entry - Labels []*github.Label -} - -func (p GhPrClientDetails) CommentOnPr(commentBody string) error { - commentBody = "\n" + commentBody - - comment := &github.IssueComment{Body: &commentBody} - _, resp, err := p.Ghclient.Issues.CreateComment(p.Ctx, p.Owner, p.Repo, p.PrNumber, comment) - prom.InstrumentGhCall(resp) - if err != nil { - p.PrLogger.Errorf("Could not comment in PR: err=%s\n%v\n", err, resp) - } - return err -} - -func DoesPrHasLabel(eventPayload github.PullRequestEvent, name string) bool { - result := false - for _, prLabel := range eventPayload.PullRequest.Labels { - if *prLabel.Name == name { - result = true - break - } - } - return result -} - -func (p *GhPrClientDetails) ToggleCommitStatus(context string, user string) error { - var r error - listOpts := &github.ListOptions{} - - initialStatuses, resp, err := p.Ghclient.Repositories.ListStatuses(p.Ctx, p.Owner, p.Repo, p.Ref, listOpts) - prom.InstrumentGhCall(resp) - if err != nil { - p.PrLogger.Errorf("Failed to fetch existing statuses for commit %s, err=%s", p.Ref, err) - r = err - } - - for _, commitStatus := range initialStatuses { - if *commitStatus.Context == context { - if *commitStatus.State != "success" { - p.PrLogger.Infof("%s Toggled %s(%s) to success", user, context, *commitStatus.State) - *commitStatus.State = "success" - _, resp, err := p.Ghclient.Repositories.CreateStatus(p.Ctx, p.Owner, p.Repo, p.PrSHA, commitStatus) - prom.InstrumentGhCall(resp) - if err != nil { - p.PrLogger.Errorf("Failed to create context %s, err=%s", context, err) - r = err - } - } else { - p.PrLogger.Infof("%s Toggled %s(%s) to failure", user, context, *commitStatus.State) - *commitStatus.State = "failure" - _, resp, err := p.Ghclient.Repositories.CreateStatus(p.Ctx, p.Owner, p.Repo, p.PrSHA, commitStatus) - prom.InstrumentGhCall(resp) - if err != nil { - p.PrLogger.Errorf("Failed to create context %s, err=%s", context, err) - r = err - } - } - break - } - } - - return r -} - -func SetCommitStatus(ghPrClientDetails GhPrClientDetails, state string) { - // TODO change all these values - context := " \ No newline at end of file diff --git a/internal/pkg/githubapi/webhook_proxy.go b/internal/pkg/githubapi/webhook_proxy.go index c3eadb3..bb0d223 100644 --- a/internal/pkg/githubapi/webhook_proxy.go +++ b/internal/pkg/githubapi/webhook_proxy.go @@ -17,11 +17,6 @@ import ( "golang.org/x/exp/maps" ) -// @Title -// @Description -// @Author -// @Update - func generateListOfChangedFiles(eventPayload *github.PushEvent) []string { fileList := map[string]bool{} // using map for uniqueness