diff --git a/atlasaction/action.go b/atlasaction/action.go
index 2bb455b8..65110d91 100644
--- a/atlasaction/action.go
+++ b/atlasaction/action.go
@@ -13,6 +13,7 @@ import (
"fmt"
"io"
"net/http"
+ "path"
"slices"
"strconv"
"strings"
@@ -140,6 +141,9 @@ func MigrateLint(ctx context.Context, client *atlasexec.Client, act *githubactio
if err := publish(act, dirName, summary.String()); err != nil {
return err
}
+ if err := addChecks(act, &payload); err != nil {
+ return err
+ }
if errors.Is(err, atlasexec.LintErr) {
return fmt.Errorf("lint completed with errors, see report: %s", payload.URL)
}
@@ -213,6 +217,41 @@ func publish(act *githubactions.Action, dirName, summary string) error {
return g.createIssueComment(prNumber, r, ghContext.Repository, ghToken)
}
+// addChecks runs to the pull request for the given payload.
+func addChecks(act *githubactions.Action, payload *atlasexec.SummaryReport) error {
+ dir := payload.Env.Dir
+ for _, file := range payload.Files {
+ filePath := path.Join(dir, file.Name)
+ if file.Error != "" && len(file.Reports) == 0 {
+ act.WithFieldsMap(map[string]string{
+ "file": filePath,
+ "line": "1",
+ }).Errorf(file.Error)
+ continue
+ }
+ for _, report := range file.Reports {
+ for _, diag := range report.Diagnostics {
+ msg := diag.Text
+ if diag.Code != "" {
+ msg = fmt.Sprintf("%v (%v)\n\nDetails: https://atlasgo.io/lint/analyzers#%v", msg, diag.Code, diag.Code)
+ }
+ lines := strings.Split(file.Text[:diag.Pos], "\n")
+ act = act.WithFieldsMap(map[string]string{
+ "file": filePath,
+ "line": strconv.Itoa(max(1, len(lines))),
+ "title": report.Text,
+ })
+ if file.Error != "" {
+ act.Errorf(msg)
+ } else {
+ act.Noticef(msg)
+ }
+ }
+ }
+ }
+ return nil
+}
+
type (
githubIssueComment struct {
ID int `json:"id"`
diff --git a/atlasaction/action_test.go b/atlasaction/action_test.go
index 39d6d221..661ce5c7 100644
--- a/atlasaction/action_test.go
+++ b/atlasaction/action_test.go
@@ -381,6 +381,10 @@ func TestMigrateLint(t *testing.T) {
require.Contains(t, sum, "2 new migration files detected")
require.Contains(t, sum, "1 error found")
require.Contains(t, sum, ``)
+ out := tt.out.String()
+ require.Contains(t, out, "error file=testdata/migrations_destructive/20230925192914.sql")
+ require.Contains(t, out, "destructive changes detected")
+ require.Contains(t, out, "Details: https://atlasgo.io/lint/analyzers#DS102")
})
t.Run("lint summary - with diagnostics", func(t *testing.T) {
tt := newT(t)
@@ -396,6 +400,10 @@ func TestMigrateLint(t *testing.T) {
require.Contains(t, sum, "2 new migration files detected")
require.Contains(t, sum, "1 issue found")
require.Contains(t, sum, ``)
+ out := tt.out.String()
+ require.Contains(t, out, "notice file=testdata/diagnostics/20231016114135_add_not_null.sql")
+ require.Contains(t, out, "data dependent changes detected")
+ require.Contains(t, out, "Details: https://atlasgo.io/lint/analyzers#MF103")
})
t.Run("lint summary - lint success", func(t *testing.T) {
tt := newT(t)