Skip to content

Commit

Permalink
test pr
Browse files Browse the repository at this point in the history
  • Loading branch information
ronenlu committed Feb 18, 2024
1 parent 933901b commit f9bd0cc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
28 changes: 22 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,8 @@ 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)
fmt.Println("body sent:", string(buf))
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 @@ -463,14 +466,27 @@ func createRunContext(act *githubactions.Action) (*atlasexec.RunContext, error)
}

type githubTriggerEvent struct {
PullRequest struct {
Number int `mapstructure:"number"`
Head struct {
SHA string `mapstructure:"sha"`
} `mapstructure:"head"`
} `mapstructure:"pull_request"`
HeadCommit struct {
URL string `mapstructure:"url"`
} `mapstructure:"head_commit"`
PullRequestNumber int `mapstructure:"number"`
}

func triggerEvent(ghContext *githubactions.GitHubContext) (*githubTriggerEvent, error) {
var event githubTriggerEvent
pr := ghContext.Event["pull_request"]
if pr != nil {
sha := ghContext.Event["pull_request"].(map[string]interface{})["head"].(map[string]interface{})["sha"]
fmt.Println("sha:", sha)
prNumber := ghContext.Event["pull_request"].(map[string]interface{})["number"]

fmt.Println("prNumber:", prNumber)
}
if err := mapstructure.Decode(ghContext.Event, &event); err != nil {
return nil, fmt.Errorf("failed to parse push event: %v", err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
-- drop table t1;
drop table t1;
4 changes: 2 additions & 2 deletions atlasaction/testdata/migrations_destructive/atlas.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
h1:jw+3IjeTY+1ngJYKRc/Ddq8hJkBWpVRnF8qS61zspJg=
h1:H/F2w8bIg7dfvQR4lLFOLhf+bZLwlCAPXMBVJb1VKLc=
20230922132634_init.sql h1:Q+dJaaJDja1u1qEni6E0SfC4dMXhHgW2F1ybAtgcgeE=
20230925192914.sql h1:2YTCgLJQ5t3t71z3zGGRNSaWBItjTXF9zEcQICGIZkc=
20230925192914.sql h1:45yfGQkVGdeGJNj/MEF9xtJdvtW2dWnpvMIhsVjIkiA=

0 comments on commit f9bd0cc

Please sign in to comment.