-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add link to linting report to PR summary (#113)
- Loading branch information
1 parent
34fba85
commit 7b991aa
Showing
6 changed files
with
211 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package cli | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"regexp" | ||
|
||
"github.com/speakeasy-api/sdk-generation-action/internal/environment" | ||
) | ||
|
||
type RunResults struct { | ||
LintingReport string | ||
} | ||
|
||
func Run(sourcesOnly bool, installationURLs map[string]string, repoURL string, repoSubdirectories map[string]string) (*RunResults, error) { | ||
args := []string{ | ||
"run", | ||
} | ||
|
||
if sourcesOnly { | ||
args = append(args, "-s", "all") | ||
} else { | ||
specifiedTarget := environment.SpecifiedTarget() | ||
if specifiedTarget != "" { | ||
args = append(args, "-t", specifiedTarget) | ||
} else { | ||
args = append(args, "-t", "all") | ||
} | ||
urls, err := json.Marshal(installationURLs) | ||
if err != nil { | ||
return nil, fmt.Errorf("error marshalling installation urls: %w", err) | ||
} | ||
args = append(args, "--installationURLs", string(urls)) | ||
|
||
subdirs, err := json.Marshal(repoSubdirectories) | ||
if err != nil { | ||
return nil, fmt.Errorf("error marshalling repo subdirectories: %w", err) | ||
} | ||
args = append(args, "--repo-subdirs", string(subdirs)) | ||
} | ||
|
||
if repoURL != "" { | ||
args = append(args, "-r", repoURL) | ||
} | ||
|
||
if environment.ForceGeneration() { | ||
fmt.Println("force input enabled - setting SPEAKEASY_FORCE_GENERATION=true") | ||
os.Setenv("SPEAKEASY_FORCE_GENERATION", "true") | ||
} | ||
|
||
//if environment.ShouldOutputTests() { | ||
// TODO: Add CLI flag for outputting tests | ||
//} | ||
|
||
out, err := runSpeakeasyCommand(args...) | ||
if err != nil { | ||
return nil, fmt.Errorf("error running workflow: %w - %s", err, out) | ||
} | ||
|
||
lintingReportURL := getLintingReportURL(out) | ||
|
||
fmt.Println(out) | ||
return &RunResults{ | ||
LintingReport: lintingReportURL, | ||
}, nil | ||
} | ||
|
||
var lintingReportRegex = regexp.MustCompile(`(?m).*?(https:\/\/app.speakeasyapi.dev\/org\/.*?\/.*?\/linting-report\/.*?)\s`) | ||
|
||
func getLintingReportURL(out string) string { | ||
matches := lintingReportRegex.FindStringSubmatch(out) | ||
if len(matches) > 1 { | ||
return matches[1] | ||
} | ||
|
||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cli | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_getLintingReportURL(t *testing.T) { | ||
type args struct { | ||
out string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
name: "success", | ||
args: args{ | ||
out: `INFO Running source validationtest... | ||
INFO Validating OpenAPI spec... | ||
INFO Using ruleset thisRuleset from validationtest/.speakeasy/lint.yaml | ||
INFO Validation report available to view at: https://app.speakeasyapi.dev/org/test/test/linting-report/7aebdf7581f7f04430709644c2e304b7 | ||
WARN validation warn: [line 12] any-paths - More than a single path exists, there are 1 | ||
INFO | ||
OpenAPI spec validation complete. 0 errors, 1 warnings, 0 hints`, | ||
}, | ||
want: "https://app.speakeasyapi.dev/org/test/test/linting-report/7aebdf7581f7f04430709644c2e304b7", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
url := getLintingReportURL(tt.args.out) | ||
assert.Equal(t, tt.want, url) | ||
}) | ||
} | ||
} |
Oops, something went wrong.