Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ronenlu committed Feb 18, 2024
1 parent 933901b commit e689e04
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions atlasaction/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (g *githubAPI) addSummary(act *githubactions.Action, summary string) error
return err
}
act.AddStepSummary(summary)
prNumber := event.PullRequestNumber
prNumber := event.PullRequest.Number
if prNumber == 0 {
return nil
}
Expand Down Expand Up @@ -283,15 +283,17 @@ func (g *githubAPI) addSuggestions(act *githubactions.Action, payload *atlasexec
}
for _, file := range payload.Files {
filePath := path.Join(payload.Env.Dir, file.Name)
prNumber := event.PullRequest.Number
commitID := event.PullRequest.Head.SHA
for _, report := range file.Reports {
for _, s := range report.SuggestedFixes {
if err := g.commentSuggestion(event.PullRequestNumber, ghContext.SHA, filePath, s); err != nil {
if err := g.commentSuggestion(prNumber, commitID, filePath, s); err != nil {
return err
}
}
for _, d := range report.Diagnostics {
for _, s := range d.SuggestedFixes {
if err := g.commentSuggestion(event.PullRequestNumber, ghContext.SHA, filePath, s); err != nil {
if err := g.commentSuggestion(prNumber, commitID, filePath, s); err != nil {
return err
}
}
Expand Down Expand Up @@ -404,7 +406,7 @@ func (g *githubAPI) updateComment(id int, content io.Reader) error {
}

// commentSuggestion creates a suggestion comment on the pull request.
func (g *githubAPI) commentSuggestion(prID int, commitID, filePath string, suggestion sqlcheck.SuggestedFix) error {
func (g *githubAPI) commentSuggestion(prNumber int, commitID, filePath string, suggestion sqlcheck.SuggestedFix) error {
prComment := pullRequestComment{
Body: fmt.Sprintf("```suggestion\n%s\n```", suggestion.TextEdit.NewText),
Path: filePath,
Expand All @@ -420,7 +422,7 @@ func (g *githubAPI) commentSuggestion(prID int, commitID, filePath string, sugge
if err != nil {
return err
}
url := fmt.Sprintf("%v/repos/%v/pulls/%v/comments", g.baseURL, g.repo, prID)
url := fmt.Sprintf("%v/repos/%v/pulls/%v/comments", g.baseURL, g.repo, prNumber)
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(buf))
if err != nil {
return err
Expand Down Expand Up @@ -466,7 +468,12 @@ type githubTriggerEvent struct {
HeadCommit struct {
URL string `mapstructure:"url"`
} `mapstructure:"head_commit"`
PullRequestNumber int `mapstructure:"number"`
PullRequest struct {
Number int `mapstructure:"number"`
Head struct {
SHA string `mapstructure:"sha"`
} `mapstructure:"head"`
} `mapstructure:"pull_request"`
}

func triggerEvent(ghContext *githubactions.GitHubContext) (*githubTriggerEvent, error) {
Expand Down

0 comments on commit e689e04

Please sign in to comment.