Skip to content

Commit

Permalink
feat: improve oss quickfix and lense titles (#604)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch authored Jul 24, 2024
1 parent ddbbe9b commit c9e0472
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 66 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
- name: Prepare git
run: git config --global core.autocrlf false

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version-file: "./go.mod"

Expand All @@ -37,7 +37,7 @@ jobs:

- name: Cache Pact CLI tools
id: cache-pact
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/pact
key: ${{ runner.os }}-pact
Expand All @@ -49,7 +49,7 @@ jobs:
make tools
- name: Cache Go modules
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
Expand Down Expand Up @@ -86,17 +86,17 @@ jobs:
- name: Prepare git
run: git config --global core.autocrlf false

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version-file: "./go.mod"

- name: Cache Pact CLI tools
if: matrix.os != 'windows-latest'
id: cache-pact
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/pact
key: ${{ runner.os }}-pact
Expand Down Expand Up @@ -151,7 +151,7 @@ jobs:
name: proxy-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Run proxy tests
env:
Expand All @@ -167,14 +167,14 @@ jobs:
- name: Prepare git
run: git config --global core.autocrlf false

- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ secrets.HAMMERHEAD_GITHUB_PAT_SNYKLS }}

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version-file: "./go.mod"

Expand All @@ -195,7 +195,7 @@ jobs:
name: test-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # does an unshallow checkout with tags & branches

Expand All @@ -204,7 +204,7 @@ jobs:
sed -En 's/^go[[:space:]]+([[:digit:].]+)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

Expand All @@ -219,11 +219,11 @@ jobs:
echo $LICENSES
- name: Do test release with goreleaser
uses: goreleaser/goreleaser-action@v3
uses: goreleaser/goreleaser-action@v6
env:
LICENSES: ${{ steps.create_license_report.outputs.LICENSES }}
with:
args: release --clean --snapshot --skip=publish
args: release --clean --snapshot

- name: Output compiled licenses
run: |
Expand Down
39 changes: 5 additions & 34 deletions .github/workflows/instance-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ jobs:
instance-tests:
strategy:
matrix:
environment: [MT1, MT3]
environment: [Standard, MT1, MT3]
name: instance tests
environment: ${{matrix.environment}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version-file: "./go.mod"

- name: Cache Go modules
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
Expand All @@ -50,41 +50,12 @@ jobs:
- name: Run Instance Tests
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
SNYK_TOKEN_CONSISTENT_IGNORES: ${{secrets.SNYK_TOKEN_CONSISTENT_IGNORES }}
SNYK_API: ${{ secrets.SNYK_API }}
run: |
make instance-test
instance-standard-test:
name: instance tests (Standard)
runs-on: ubuntu-latest
environment: Standard
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version-file: "./go.mod"

- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-

- name: Run Instance Tests on Standard Environment
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
SNYK_API: ${{ secrets.SNYK_API }}
run: |
make instance-standard-test
slackNotification:
needs: [instance-tests, instance-standard-test]
needs: [instance-tests]
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' && (needs.instance-tests.result != 'success' || needs.instance-standard-test.result != 'success') }}
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

- name: Cache Pact CLI tools
id: cache-pact
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/pact
key: ${{ runner.os }}-pact
Expand All @@ -60,7 +60,7 @@ jobs:
make tools
- name: Cache Go modules
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
Expand Down
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,7 @@ proxy-test:

instance-test:
@echo "==> Running instance tests"
@export SMOKE_TESTS=1 && cd application/server && go test $(TIMEOUT) -failfast -run Test_SmokeWorkspaceScan && cd -

instance-standard-test:
@echo "==> Running instance tests for the standard environment"
@export SMOKE_TESTS=1 && cd application/server && go test $(TIMEOUT) -failfast -run Test_Smoke && cd -
@echo "==> Checking Eclipse storage buckets..."
@export SMOKE_TESTS=1 && cd application/server && go test $(TIMEOUT) -failfast -run Test_SmokeInstanceTest && cd -
@curl -sSL https://static.snyk.io/eclipse/stable/p2.index

## build: Build binary for default local system's OS and architecture.
Expand Down
12 changes: 11 additions & 1 deletion application/codeaction/codeaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,18 @@ func (c *CodeActionsService) GetCodeActions(params types.CodeActionParams) []typ
func (c *CodeActionsService) updateIssuesWithQuickFix(quickFixGroupables []types.Groupable, issues []snyk.Issue) []snyk.Issue {
// we only allow one quickfix, so it needs to be grouped
quickFix := c.getQuickFixAction(quickFixGroupables)
fixable := len(quickFixGroupables)
unfixable := len(issues) - fixable
// update title with number of issues
quickFix.Title = fmt.Sprintf("%s and fix %d issues", quickFix.Title, len(quickFixGroupables))
plural := ""
if fixable > 1 {
plural = "s"
}
unfixableSuffix := ""
if unfixable > 0 {
unfixableSuffix = fmt.Sprintf(" (%d unfixable)", unfixable)
}
quickFix.Title = fmt.Sprintf("%s and fix %d issue%s%s", quickFix.Title, fixable, plural, unfixableSuffix)

var updatedIssues []snyk.Issue
for _, issue := range issues {
Expand Down
49 changes: 41 additions & 8 deletions application/server/server_smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ import (
"github.com/snyk/snyk-ls/internal/uri"
)

func Test_SmokeInstanceTest(t *testing.T) {
ossFile := "package.json"
codeFile := "app.js"
testutil.CreateDummyProgressListener(t)
endpoint := os.Getenv("SNYK_API")
if endpoint == "" {
t.Setenv("SNYK_API", "https://api.snyk.io")
}
runSmokeTest(t, "https://github.com/snyk-labs/nodejs-goof", "0336589", ossFile, codeFile, false, true, endpoint)
}

func Test_SmokeWorkspaceScan(t *testing.T) {
ossFile := "package.json"
iacFile := "main.tf"
Expand All @@ -68,7 +79,7 @@ func Test_SmokeWorkspaceScan(t *testing.T) {

tests := []test{
{
name: "OSS and Code",
name: "OSS_and_Code",
repo: "https://github.com/snyk-labs/nodejs-goof",
commit: "0336589",
file1: ossFile,
Expand All @@ -77,7 +88,7 @@ func Test_SmokeWorkspaceScan(t *testing.T) {
hasVulns: true,
},
{
name: "OSS and Code with V1 endpoint",
name: "OSS_and_Code_with_V1_endpoint",
repo: "https://github.com/snyk-labs/nodejs-goof",
commit: "0336589",
file1: ossFile,
Expand All @@ -86,7 +97,7 @@ func Test_SmokeWorkspaceScan(t *testing.T) {
endpoint: path.Join(endpoint, "/v1"),
},
{
name: "OSS and Code with consistent ignores",
name: "OSS_and_Code_with_consistent_ignores",
repo: "https://github.com/snyk-labs/nodejs-goof",
commit: "0336589",
file1: ossFile,
Expand All @@ -95,7 +106,7 @@ func Test_SmokeWorkspaceScan(t *testing.T) {
hasVulns: true,
},
{
name: "IaC and Code",
name: "IaC_and_Code",
repo: "https://github.com/deepcodeg/snykcon-goof.git",
commit: "eba8407",
file1: iacFile,
Expand All @@ -104,7 +115,7 @@ func Test_SmokeWorkspaceScan(t *testing.T) {
hasVulns: true,
},
{
name: "Code without vulns",
name: "Code_without_vulns",
repo: "https://github.com/imagec/simple-repo",
commit: "75bcc55",
file1: "",
Expand All @@ -113,7 +124,7 @@ func Test_SmokeWorkspaceScan(t *testing.T) {
hasVulns: false,
},
{
name: "IaC and Code with consistent ignores",
name: "IaC_and_Code_with_consistent_ignores",
repo: "https://github.com/deepcodeg/snykcon-goof.git",
commit: "eba8407",
file1: iacFile,
Expand All @@ -122,7 +133,7 @@ func Test_SmokeWorkspaceScan(t *testing.T) {
hasVulns: true,
},
{
name: "Two upload batches",
name: "Two_upload_batches",
repo: "https://github.com/apache/maven",
commit: "18725ec1e",
file1: "",
Expand Down Expand Up @@ -497,10 +508,22 @@ func checkOnlyOneQuickFixCodeAction(t *testing.T, jsonRPCRecorder *testutil.Json

quickFixCount := 0
for _, action := range actions {
if strings.Contains(action.Title, "Upgrade to") {
isQuickfixAction := strings.Contains(action.Title, "Upgrade to")
if isQuickfixAction {
quickFixCount++
atLeastOneQuickfixActionFound = true
}

// "cfenv": "^1.0.4", 1 fixable issue
if issue.Range.Start.Line == 19 && isQuickfixAction {
assert.Contains(t, action.Title, "and fix 1 issue")
assert.NotContains(t, action.Title, "and fix 1 issues")
}

// "tap": "^11.1.3", 12 fixable, 11 unfixable
if issue.Range.Start.Line == 46 && isQuickfixAction {
assert.Contains(t, action.Title, "and fix 12 issues (11 unfixable)")
}
}
// no issues should have more than one quickfix
if quickFixCount > 1 {
Expand Down Expand Up @@ -541,6 +564,16 @@ func checkOnlyOneCodeLens(t *testing.T, jsonRPCRecorder *testutil.JsonRPCRecorde
lensCount++
atLeastOneOneIssueWithCodeLensFound = true
}
// "cfenv": "^1.0.4", 1 fixable issue
if lens.Range.Start.Line == 19 {
assert.Contains(t, lens.Command.Title, "and fix 1 issue")
assert.NotContains(t, lens.Command.Title, "and fix 1 issues")
}

// "tap": "^11.1.3", 12 fixable, 11 unfixable
if lens.Range.Start.Line == 46 {
assert.Contains(t, lens.Command.Title, "and fix 12 issues (11 unfixable)")
}
}
}
assert.Truef(t, atLeastOneOneIssueWithCodeLensFound, "expected to find at least one code lens")
Expand Down
14 changes: 13 additions & 1 deletion domain/ide/codelens/codelens.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
type lensesWithIssueCount struct {
lensCommands []types.CommandData
issueCount int
totalIssues int
}

func GetFor(filePath string) (lenses []sglsp.CodeLens) {
Expand All @@ -49,6 +50,7 @@ func GetFor(filePath string) (lenses []sglsp.CodeLens) {
lensesWithIssueCountsForRange = &lensesWithIssueCount{
lensCommands: []types.CommandData{},
issueCount: 0,
totalIssues: len(f.IssuesForRange(filePath, issue.Range)),
}
}
lensesWithIssueCountsForRange.lensCommands = append(lensesWithIssueCountsForRange.lensCommands, lens)
Expand Down Expand Up @@ -85,7 +87,17 @@ func getLensCommands(lensesWithIssueCount *lensesWithIssueCount) []types.Command
// right now we can always group by max semver version, as
// code only has one quickfix available, and iac none at all
qf, ok := types.MaxSemver()(lensCommands).(types.CommandData)
qf.Title = fmt.Sprintf("%s and fix %d issues", qf.Title, lensesWithIssueCount.issueCount)
plural := ""
fixable := lensesWithIssueCount.issueCount
unfixable := lensesWithIssueCount.totalIssues - fixable
if fixable > 1 {
plural = "s"
}
unfixableSuffix := ""
if unfixable > 1 {
unfixableSuffix = fmt.Sprintf(" (%d unfixable)", unfixable)
}
qf.Title = fmt.Sprintf("%s and fix %d issue%s%s", qf.Title, fixable, plural, unfixableSuffix)
if ok {
lenses = append(lenses, qf)
}
Expand Down

0 comments on commit c9e0472

Please sign in to comment.