From d860f4087b8e26383c5f75d586c9fe3e8c46ec81 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Wed, 4 Dec 2024 11:58:43 -0500 Subject: [PATCH 01/33] add gh action workflow to mirror circle ci --- .github/workflows/main.yml | 97 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..6aa4b7a9 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,97 @@ +# .github/workflows/ci.yml +name: CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + go-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.22 + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -yqq git python3-pip + go install github.com/jstemmer/go-junit-report@v1.0.0 + go install github.com/kyoh86/richgo@v0.3.10 + sudo pip install pre-commit + - name: Run pre-commit + run: | + pre-commit install + pre-commit run -a golangci-lint + - name: Set up Code Climate test-reporter + run: | + curl -sS -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + chmod +x ./cc-test-reporter + - name: Run tests + env: + CIRCLE_TEST_REPORTS: /tmp/circle-reports + CIRCLE_ARTIFACTS: /tmp/circle-artifacts + run: | + mkdir -p $CIRCLE_TEST_REPORTS + mkdir -p $CIRCLE_ARTIFACTS + trap "go-junit-report < $CIRCLE_ARTIFACTS/report.txt > $CIRCLE_TEST_REPORTS/junit.xml" EXIT + if [ -z "$DISABLE_COVERAGE" ]; then + go_cover_args="-covermode=atomic -coverpkg=./... -coverprofile /tmp/circle-artifacts/coverage.txt" + fi + go test -race $go_cover_args -v $(go list ./... | grep -v /vendor/) | tee >(richgo testfilter) > $CIRCLE_ARTIFACTS/report.txt + if [[ -z "$DISABLE_COVERAGE" && -n "$CC_TEST_REPORTER_ID" ]]; then + ./cc-test-reporter format-coverage $CIRCLE_ARTIFACTS/coverage.txt -t gocov --output $CIRCLE_ARTIFACTS/coverage.json + ./cc-test-reporter upload-coverage --input $CIRCLE_ARTIFACTS/coverage.json + fi + - name: Generate coverage report + if: always() + run: | + if [ -z "$DISABLE_COVERAGE" ]; then + go tool cover -html=$CIRCLE_ARTIFACTS/coverage.txt -o $CIRCLE_ARTIFACTS/coverage.html + fi + - name: Store test results + uses: actions/upload-artifact@v2 + with: + name: test-results + path: /tmp/circle-reports + - name: Store artifacts + uses: actions/upload-artifact@v2 + with: + name: artifacts + path: /tmp/circle-artifacts + + test-publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.22 + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install rpm + - name: Run test-publish + run: make test-publish + + github-actions-docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install python3-pip + sudo pip install pre-commit + npm install action-docs + - name: Run pre-commit + run: | + pre-commit install + pre-commit run -a github-action-docs \ No newline at end of file From 11034ba7e9feec9323180120bc5380f1170c3676 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Wed, 4 Dec 2024 11:59:40 -0500 Subject: [PATCH 02/33] add newline --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6aa4b7a9..932c2e59 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -94,4 +94,4 @@ jobs: - name: Run pre-commit run: | pre-commit install - pre-commit run -a github-action-docs \ No newline at end of file + pre-commit run -a github-action-docs From abff4d5b718fa6f7b6ea84c24e002a69c50b9877 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Wed, 4 Dec 2024 12:09:14 -0500 Subject: [PATCH 03/33] simplify the workflow --- .github/workflows/main.yml | 117 ++++++++++--------------------------- 1 file changed, 31 insertions(+), 86 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 932c2e59..d4b6396f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,97 +1,42 @@ -# .github/workflows/ci.yml -name: CI +name: Test and Generate Docs -on: - push: - branches: - - main - pull_request: - branches: - - main +on: pull_request jobs: - go-test: + go-tests: runs-on: ubuntu-latest + steps: - - uses: actions/checkout@v2 + - name: Checkout Code + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: 1.22 - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -yqq git python3-pip - go install github.com/jstemmer/go-junit-report@v1.0.0 - go install github.com/kyoh86/richgo@v0.3.10 - sudo pip install pre-commit - - name: Run pre-commit - run: | - pre-commit install - pre-commit run -a golangci-lint - - name: Set up Code Climate test-reporter - run: | - curl -sS -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter - - name: Run tests - env: - CIRCLE_TEST_REPORTS: /tmp/circle-reports - CIRCLE_ARTIFACTS: /tmp/circle-artifacts - run: | - mkdir -p $CIRCLE_TEST_REPORTS - mkdir -p $CIRCLE_ARTIFACTS - trap "go-junit-report < $CIRCLE_ARTIFACTS/report.txt > $CIRCLE_TEST_REPORTS/junit.xml" EXIT - if [ -z "$DISABLE_COVERAGE" ]; then - go_cover_args="-covermode=atomic -coverpkg=./... -coverprofile /tmp/circle-artifacts/coverage.txt" - fi - go test -race $go_cover_args -v $(go list ./... | grep -v /vendor/) | tee >(richgo testfilter) > $CIRCLE_ARTIFACTS/report.txt - if [[ -z "$DISABLE_COVERAGE" && -n "$CC_TEST_REPORTER_ID" ]]; then - ./cc-test-reporter format-coverage $CIRCLE_ARTIFACTS/coverage.txt -t gocov --output $CIRCLE_ARTIFACTS/coverage.json - ./cc-test-reporter upload-coverage --input $CIRCLE_ARTIFACTS/coverage.json - fi - - name: Generate coverage report - if: always() - run: | - if [ -z "$DISABLE_COVERAGE" ]; then - go tool cover -html=$CIRCLE_ARTIFACTS/coverage.txt -o $CIRCLE_ARTIFACTS/coverage.html - fi - - name: Store test results - uses: actions/upload-artifact@v2 - with: - name: test-results - path: /tmp/circle-reports - - name: Store artifacts - uses: actions/upload-artifact@v2 + uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed with: - name: artifacts - path: /tmp/circle-artifacts + go-version-file: go.mod - test-publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up Go - uses: actions/setup-go@v3 + - name: Set up Python + uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b with: - go-version: 1.22 - - name: Install dependencies + python-version: '3.x' + + - name: Install pre-commit run: | - sudo apt-get update - sudo apt-get install rpm - - name: Run test-publish - run: make test-publish + python -m pip install --upgrade pip + pip install pre-commit - github-actions-docs: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install python3-pip - sudo pip install pre-commit - npm install action-docs - - name: Run pre-commit - run: | - pre-commit install - pre-commit run -a github-action-docs + - name: Run pre-commit hooks + run: pre-commit run --all-files + + - name: Run tests with gotestsum + run: | + mkdir -p ${{ github.workspace }}/artifacts + mkdir -p ${{ github.workspace }}/reports + GONFALON_MODE=test \ + gotestsum --packages="./..." \ + --junitfile ${{ github.workspace }}/reports/go-test_go_tests.xml \ + --jsonfile ${{ github.workspace }}/artifacts/go-test_go_tests.json \ + --rerun-fails=2 \ + --rerun-fails-max-failures=10 \ + --rerun-fails-report ${{ github.workspace }}/artifacts/rerun_tests_go_tests.txt \ + -- -p=1 From a840939fe2bcc9055bd73a9282ab2c0097a9b26a Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Wed, 4 Dec 2024 13:58:19 -0500 Subject: [PATCH 04/33] make sure test run sequentially --- .github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d4b6396f..3bda5f7f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,5 +38,4 @@ jobs: --jsonfile ${{ github.workspace }}/artifacts/go-test_go_tests.json \ --rerun-fails=2 \ --rerun-fails-max-failures=10 \ - --rerun-fails-report ${{ github.workspace }}/artifacts/rerun_tests_go_tests.txt \ - -- -p=1 + --rerun-fails-report ${{ github.workspace }}/artifacts/rerun_tests_go_tests.txt From 9a6f01f62247b8afc32cbe98bf423073795cd1cb Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Wed, 4 Dec 2024 14:35:17 -0500 Subject: [PATCH 05/33] log file path --- vendor/github.com/go-git/go-git/v5/worktree_status.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vendor/github.com/go-git/go-git/v5/worktree_status.go b/vendor/github.com/go-git/go-git/v5/worktree_status.go index dd9b2439..6450fbaa 100644 --- a/vendor/github.com/go-git/go-git/v5/worktree_status.go +++ b/vendor/github.com/go-git/go-git/v5/worktree_status.go @@ -3,6 +3,7 @@ package git import ( "bytes" "errors" + "fmt" "io" "os" "path" @@ -429,6 +430,7 @@ func (w *Worktree) AddGlob(pattern string) error { // the file added is different from the index. // if s status is nil will skip the status check and update the index anyway func (w *Worktree) doAddFile(idx *index.Index, s Status, path string, ignorePattern []gitignore.Pattern) (added bool, h plumbing.Hash, err error) { + fmt.Println("doAddFile", path) if s != nil && s.File(path).Worktree == Unmodified { return false, h, nil } From bb5d29e8b2ce000642106d3ad583cb7280e2af29 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Wed, 4 Dec 2024 15:49:44 -0500 Subject: [PATCH 06/33] log write path --- internal/git/git_integration_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/git/git_integration_test.go b/internal/git/git_integration_test.go index fe110a88..540b0163 100644 --- a/internal/git/git_integration_test.go +++ b/internal/git/git_integration_test.go @@ -1,6 +1,7 @@ package git import ( + "errors" "io" "os" "path/filepath" @@ -174,6 +175,7 @@ func copyFile(t *testing.T, src, dst string) { } func createRepoFile(t *testing.T, path string, content *string) { + require.NoError(t, errors.New(repoPath(path))) flagFile, err := os.Create(repoPath(path)) require.NoError(t, err) if content != nil { From ca370e682656e66455db74fe334a937b364c84d9 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Thu, 5 Dec 2024 09:14:53 -0500 Subject: [PATCH 07/33] remove error --- internal/git/git_integration_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/git/git_integration_test.go b/internal/git/git_integration_test.go index 540b0163..fe110a88 100644 --- a/internal/git/git_integration_test.go +++ b/internal/git/git_integration_test.go @@ -1,7 +1,6 @@ package git import ( - "errors" "io" "os" "path/filepath" @@ -175,7 +174,6 @@ func copyFile(t *testing.T, src, dst string) { } func createRepoFile(t *testing.T, path string, content *string) { - require.NoError(t, errors.New(repoPath(path))) flagFile, err := os.Create(repoPath(path)) require.NoError(t, err) if content != nil { From 7a975dda3a200d5c10e2d29dc34118bfa9c6943c Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Thu, 5 Dec 2024 09:22:42 -0500 Subject: [PATCH 08/33] remove uneeded variable --- .github/workflows/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3bda5f7f..b5ca8514 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,7 +32,6 @@ jobs: run: | mkdir -p ${{ github.workspace }}/artifacts mkdir -p ${{ github.workspace }}/reports - GONFALON_MODE=test \ gotestsum --packages="./..." \ --junitfile ${{ github.workspace }}/reports/go-test_go_tests.xml \ --jsonfile ${{ github.workspace }}/artifacts/go-test_go_tests.json \ From d2a07316a4f4394f27d3d9cd82f0aa52c6ef8fff Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Thu, 5 Dec 2024 09:25:49 -0500 Subject: [PATCH 09/33] add install dependencies step --- .github/workflows/main.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b5ca8514..d17b69a4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,14 +15,12 @@ jobs: with: go-version-file: go.mod - - name: Set up Python - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b - with: - python-version: '3.x' - - - name: Install pre-commit + - name: Install Dependencies run: | - python -m pip install --upgrade pip + sudo apt-get update + sudo apt-get install -y git python3-pip + go install github.com/jstemmer/go-junit-report@v1.0.0 + go install github.com/kyoh86/richgo@v0.3.10 pip install pre-commit - name: Run pre-commit hooks From c41fcd93cd2b674f84103325d0fb81f52a75d1c2 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Thu, 5 Dec 2024 09:29:29 -0500 Subject: [PATCH 10/33] remove pre commit hook --- .github/workflows/main.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d17b69a4..44e229d8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,9 +23,6 @@ jobs: go install github.com/kyoh86/richgo@v0.3.10 pip install pre-commit - - name: Run pre-commit hooks - run: pre-commit run --all-files - - name: Run tests with gotestsum run: | mkdir -p ${{ github.workspace }}/artifacts From 479a57925210fe7f4d61f7ead470abf967ad1e19 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Thu, 5 Dec 2024 09:30:18 -0500 Subject: [PATCH 11/33] only run lint via pre commit --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 44e229d8..130f0194 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,6 +23,9 @@ jobs: go install github.com/kyoh86/richgo@v0.3.10 pip install pre-commit + - name: Run pre-commit hooks + run: pre-commit run -a golangci-lint + - name: Run tests with gotestsum run: | mkdir -p ${{ github.workspace }}/artifacts From 795bba736b437683c041a79ad23809ab03c0185c Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Thu, 5 Dec 2024 09:36:16 -0500 Subject: [PATCH 12/33] add go test sum --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 130f0194..8c812964 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,6 +21,7 @@ jobs: sudo apt-get install -y git python3-pip go install github.com/jstemmer/go-junit-report@v1.0.0 go install github.com/kyoh86/richgo@v0.3.10 + go install gotest.tools/gotestsum@latest pip install pre-commit - name: Run pre-commit hooks From ba05af20d46301c3b8bced083d3212e978a18f47 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Thu, 5 Dec 2024 09:43:50 -0500 Subject: [PATCH 13/33] add github actions docs step --- .github/workflows/main.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8c812964..430ed037 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,3 +37,29 @@ jobs: --rerun-fails=2 \ --rerun-fails-max-failures=10 \ --rerun-fails-report ${{ github.workspace }}/artifacts/rerun_tests_go_tests.txt + + github-actions-docs: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + + - name: Install npm + run: sudo apt-get install -y npm + + - name: Install action-docs + run: npm install action-docs + + - name: Install Python + uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b + with: + python-version: '3.x' + + - name: Install pre-commit + run: pip install pre-commit + + - name: Run pre-commit hooks + run: pre-commit run -a github-action-docs + + - name: Generate docs + run: action-docs generate From 99cf78c51dadf7d67465edae433ae2d8e8cffe71 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Thu, 5 Dec 2024 09:46:46 -0500 Subject: [PATCH 14/33] only run pre commit --- .github/workflows/main.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 430ed037..b5cefeb2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -60,6 +60,3 @@ jobs: - name: Run pre-commit hooks run: pre-commit run -a github-action-docs - - - name: Generate docs - run: action-docs generate From 2fa72a02907dbea345d4d5d66b610827a63fd3cf Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Thu, 5 Dec 2024 09:51:46 -0500 Subject: [PATCH 15/33] remove circle ci --- .circleci/config.yml | 102 ------------------------------------------- 1 file changed, 102 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 5b304942..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,102 +0,0 @@ -version: 2.1 - -experimental: - notify: - branches: - only: - - main - -defaults: - environment: &environment - CIRCLE_TEST_REPORTS: /tmp/circle-reports - CIRCLE_ARTIFACTS: /tmp/circle-artifacts - - build_steps: &build_steps - steps: - - checkout - - run: - name: install pre dependencies - command: | - sudo apt-get install -yqq git - - run: go install github.com/jstemmer/go-junit-report@v1.0.0 - - run: go install github.com/kyoh86/richgo@v0.3.10 - - run: sudo apt-get update - - run: sudo apt-get install python3-pip - - run: sudo pip install pre-commit - - run: pre-commit install - - run: pre-commit run -a golangci-lint - - run: - name: Set up Code Climate test-reporter - command: | - curl -sS -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter - - run: - name: Run tests - command: | - mkdir -p $CIRCLE_TEST_REPORTS - mkdir -p $CIRCLE_ARTIFACTS - trap "go-junit-report < $CIRCLE_ARTIFACTS/report.txt > $CIRCLE_TEST_REPORTS/junit.xml" EXIT - if [ -z "$DISABLE_COVERAGE" ]; then - go_cover_args="-covermode=atomic -coverpkg=./... -coverprofile /tmp/circle-artifacts/coverage.txt" - fi - go test -race $go_cover_args -v $(go list ./... | grep -v /vendor/) | tee >(richgo testfilter) > $CIRCLE_ARTIFACTS/report.txt - if [[ -z "$DISABLE_COVERAGE" && -n "$CC_TEST_REPORTER_ID" ]]; then - ./cc-test-reporter format-coverage $CIRCLE_ARTIFACTS/coverage.txt -t gocov --output $CIRCLE_ARTIFACTS/coverage.json - ./cc-test-reporter upload-coverage --input $CIRCLE_ARTIFACTS/coverage.json - fi - - run: - name: Generate coverage report - command: | - if [ -z "$DISABLE_COVERAGE" ]; then - go tool cover -html=$CIRCLE_ARTIFACTS/coverage.txt -o $CIRCLE_ARTIFACTS/coverage.html - fi - when: always - - store_test_results: - path: /tmp/circle-reports - - store_artifacts: - path: /tmp/circle-artifacts - -jobs: - go-test: - docker: - - image: cimg/go:1.22 - environment: - <<: *environment - - <<: *build_steps - - test-publish: - docker: - - image: cimg/go:1.22 - steps: - - checkout - - setup_remote_docker - - run: sudo apt-get update - - run: sudo apt-get install rpm - - run: make test-publish - github-actions-docs: - docker: - - image: cimg/node:18.8.0 - steps: - - checkout - - run: sudo apt-get update - - run: sudo apt-get install python3-pip - - run: sudo pip install pre-commit - - run: pre-commit install - - run: npm install action-docs - - run: pre-commit run -a github-action-docs - -workflows: - test: - jobs: - - go-test: - filters: - tags: - only: /.*/ - - test-publish: - requires: - - go-test - - lint: - jobs: - - github-actions-docs From f7d1503843e921ad06bb4002e090e5b4ad5c0335 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Fri, 6 Dec 2024 10:40:16 -0500 Subject: [PATCH 16/33] remove print ln --- vendor/github.com/go-git/go-git/v5/worktree_status.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/vendor/github.com/go-git/go-git/v5/worktree_status.go b/vendor/github.com/go-git/go-git/v5/worktree_status.go index 6450fbaa..dd9b2439 100644 --- a/vendor/github.com/go-git/go-git/v5/worktree_status.go +++ b/vendor/github.com/go-git/go-git/v5/worktree_status.go @@ -3,7 +3,6 @@ package git import ( "bytes" "errors" - "fmt" "io" "os" "path" @@ -430,7 +429,6 @@ func (w *Worktree) AddGlob(pattern string) error { // the file added is different from the index. // if s status is nil will skip the status check and update the index anyway func (w *Worktree) doAddFile(idx *index.Index, s Status, path string, ignorePattern []gitignore.Pattern) (added bool, h plumbing.Hash, err error) { - fmt.Println("doAddFile", path) if s != nil && s.File(path).Worktree == Unmodified { return false, h, nil } From 8584bcac4f53e7256b9dc5582156bd557e28df76 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Mon, 16 Dec 2024 10:01:28 -0500 Subject: [PATCH 17/33] add step to publish the results of the test suite --- .../actions/publish-junit/action.yml | 35 +++++++++++++++++++ .github/workflows/main.yml | 10 ++++++ 2 files changed, 45 insertions(+) create mode 100644 .github/workflows/actions/publish-junit/action.yml diff --git a/.github/workflows/actions/publish-junit/action.yml b/.github/workflows/actions/publish-junit/action.yml new file mode 100644 index 00000000..7758e18e --- /dev/null +++ b/.github/workflows/actions/publish-junit/action.yml @@ -0,0 +1,35 @@ +name: Publish JUnit Tests +description: Publishes JUnit tests to one or more sources +inputs: + files: + required: true + description: The JUnit files to upload + name: + required: true + description: The name of the suite + datadog: + required: false + description: Upload to Datadog + default: 'true' + github: + required: false + description: Upload to GitHub + default: 'true' + +runs: + using: composite + steps: + - name: Report Tests to Datadog + shell: bash + if: ${{ inputs.datadog }} == 'true' + run: datadog-ci junit upload --service ${{ inputs.name }} ${{ inputs.files }} + + - name: Test Publish + uses: phoenix-actions/test-reporting@f957cd93fc2d848d556fa0d03c57bc79127b6b5e # v15 + if: ${{ inputs.github }} == 'true' + with: + name: ${{ inputs.name }} + output-to: step-summary + path: ${{ inputs.files }} + reporter: java-junit + fail-on-error: 'false' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b5cefeb2..51a736d2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,6 +38,16 @@ jobs: --rerun-fails-max-failures=10 \ --rerun-fails-report ${{ github.workspace }}/artifacts/rerun_tests_go_tests.txt + - name: Publish JUnit Tests + uses: ./.github/actions/publish-junit + env: + DD_API_KEY: ${{ secrets.DATADOG_API_KEY }} + with: + files: ${{ github.workspace }}/reports/go-test_go_tests.xml + name: find-code-references-in-pull-request + datadog: 'true' + github: 'true' + github-actions-docs: runs-on: ubuntu-latest steps: From a6d00414d09276f3aa914bc829c5a4e09a7e737d Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Mon, 16 Dec 2024 10:04:10 -0500 Subject: [PATCH 18/33] fix gh actions folder path --- .github/{workflows => }/actions/publish-junit/action.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{workflows => }/actions/publish-junit/action.yml (100%) diff --git a/.github/workflows/actions/publish-junit/action.yml b/.github/actions/publish-junit/action.yml similarity index 100% rename from .github/workflows/actions/publish-junit/action.yml rename to .github/actions/publish-junit/action.yml From 49ea11e475d254a3789658fe0d97b7bc014e722a Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Mon, 16 Dec 2024 10:07:26 -0500 Subject: [PATCH 19/33] install datadog ci --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 51a736d2..0f40f0a2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,6 +15,9 @@ jobs: with: go-version-file: go.mod + - name: Install datadog-ci + run: npm install -g @datadog/datadog-ci + - name: Install Dependencies run: | sudo apt-get update From 5e7e14d2040c132dde8e0ebee9cd9b1821509976 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Mon, 16 Dec 2024 13:53:20 -0500 Subject: [PATCH 20/33] use golang lint gh actoin --- .github/workflows/main.yml | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0f40f0a2..49b0e35c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,15 +20,19 @@ jobs: - name: Install Dependencies run: | - sudo apt-get update - sudo apt-get install -y git python3-pip go install github.com/jstemmer/go-junit-report@v1.0.0 go install github.com/kyoh86/richgo@v0.3.10 go install gotest.tools/gotestsum@latest - pip install pre-commit - - name: Run pre-commit hooks - run: pre-commit run -a golangci-lint + - name: Install golangci-lint + uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0 + with: + version: v1.53.3 + + - name: Run golangci-lint + uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 + with: + extra_args: golangci-lint --all-files - name: Run tests with gotestsum run: | @@ -57,8 +61,9 @@ jobs: - name: Checkout Code uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - - name: Install npm - run: sudo apt-get install -y npm + - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 + with: + node-version: 20 - name: Install action-docs run: npm install action-docs From f6619baf63ad176fb10075be8da09adcff128689 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Mon, 16 Dec 2024 13:57:14 -0500 Subject: [PATCH 21/33] use pre commit action --- .github/workflows/main.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 49b0e35c..5f0200e0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -68,13 +68,6 @@ jobs: - name: Install action-docs run: npm install action-docs - - name: Install Python - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b + - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 with: - python-version: '3.x' - - - name: Install pre-commit - run: pip install pre-commit - - - name: Run pre-commit hooks - run: pre-commit run -a github-action-docs + extra_args: github-action-docs --all-files From b79b7b51d4b4396a866f066ae91f55724396578d Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Mon, 16 Dec 2024 14:22:04 -0500 Subject: [PATCH 22/33] update to newest version of golangci-lint --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5f0200e0..ad3e6cab 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,9 +25,9 @@ jobs: go install gotest.tools/gotestsum@latest - name: Install golangci-lint - uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0 + uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1 with: - version: v1.53.3 + version: v6.1.1 - name: Run golangci-lint uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 From e3538928e76277eaaa614d71b1850f66cd84ca62 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Mon, 16 Dec 2024 14:28:59 -0500 Subject: [PATCH 23/33] fix version --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ad3e6cab..7c857be0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,7 +27,7 @@ jobs: - name: Install golangci-lint uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1 with: - version: v6.1.1 + version: v1.62.2 - name: Run golangci-lint uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 From 3b58eda33d61f01c0b98ca57102ad53b30c79286 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Mon, 16 Dec 2024 14:38:06 -0500 Subject: [PATCH 24/33] make linter happy --- .../package/github-actions/github-actions.go | 6 +++++- internal/git/git.go | 5 ++--- internal/ld/ld.go | 21 ++++++++++--------- options/flags.go | 7 ++++++- options/options.go | 4 ++-- search/matcher.go | 7 ++++++- 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/build/package/github-actions/github-actions.go b/build/package/github-actions/github-actions.go index 4391437c..a9619175 100644 --- a/build/package/github-actions/github-actions.go +++ b/build/package/github-actions/github-actions.go @@ -14,6 +14,10 @@ import ( o "github.com/launchdarkly/ld-find-code-refs/v2/options" ) +const ( + millisecondsInSecond = 1000 // Descriptive constant for milliseconds conversion +) + func main() { log.Init(false) dir := os.Getenv("GITHUB_WORKSPACE") @@ -55,7 +59,7 @@ func mergeGithubOptions(opts o.Options) (o.Options, error) { if event != nil { repoUrl = event.Repo.Url defaultBranch = event.Repo.DefaultBranch - updateSequenceId = int(time.Now().Unix() * 1000) // seconds to ms + updateSequenceId = int(time.Now().Unix() * millisecondsInSecond) // seconds to ms } opts.RepoType = "github" diff --git a/internal/git/git.go b/internal/git/git.go index 85fb932f..961a5354 100644 --- a/internal/git/git.go +++ b/internal/git/git.go @@ -227,7 +227,7 @@ type CommitData struct { } // FindExtinctions searches commit history for flags that had references removed recently -func (c Client) FindExtinctions(project options.Project, flags []string, matcher search.Matcher, lookback int) ([]ld.ExtinctionRep, error) { +func (c *Client) FindExtinctions(project options.Project, flags []string, matcher search.Matcher, lookback int) ([]ld.ExtinctionRep, error) { commits, err := getCommits(c.workspace, lookback) if err != nil { return nil, err @@ -342,9 +342,8 @@ func getCommits(workspace string, lookback int) ([]CommitData, error) { if err != nil { return nil, err } - commits := []CommitData{} - for i := 0; i < lookback; i++ { + for range make([]struct{}, lookback) { commit, err := logResult.Next() if err != nil { // reached end of commit tree diff --git a/internal/ld/ld.go b/internal/ld/ld.go index 13a98de0..997bf271 100644 --- a/internal/ld/ld.go +++ b/internal/ld/ld.go @@ -44,6 +44,7 @@ const ( apiVersionHeader = "LD-API-Version" v2ApiPath = "/api/v2" reposPath = "/code-refs/repositories" + shortShaLength = 7 // Descriptive constant for SHA length ) type ConfigurationError struct { @@ -76,8 +77,8 @@ func IsTransient(err error) bool { // Fallback to default backoff if header can't be parsed // https://apidocs.launchdarkly.com/#section/Overview/Rate-limiting // Method is curried in order to avoid stubbing the time package and fallback Backoff in unit tests -func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(time.Duration, time.Duration, int, *http.Response) time.Duration { - return func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration { +func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(minDuration, max time.Duration, attemptNum int, resp *http.Response) time.Duration { + return func(minDuration, max time.Duration, attemptNum int, resp *http.Response) time.Duration { if resp != nil { if resp.StatusCode == http.StatusTooManyRequests { if s, ok := resp.Header["X-Ratelimit-Reset"]; ok { @@ -95,7 +96,7 @@ func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(time } } - return fallbackBackoff(min, max, attemptNum, resp) + return fallbackBackoff(minDuration, max, attemptNum, resp) } } @@ -441,7 +442,7 @@ type ldErrorResponse struct { func (c ApiClient) do(req *h.Request) (*http.Response, error) { req.Header.Set("Authorization", c.Options.ApiKey) - req.Header.Set(apiVersionHeader, apiVersion) + req.Header.Set(apiVersionHeader, apiVersion) //nolint:canonicalheader req.Header.Set("User-Agent", c.Options.UserAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Length", strconv.FormatInt(req.ContentLength, 10)) @@ -450,15 +451,15 @@ func (c ApiClient) do(req *h.Request) (*http.Response, error) { return nil, err } + // Ensure the response body is closed + defer res.Body.Close() + // Check for all general status codes returned by the code references API, attempting to deconstruct LD error messages, if possible. switch res.StatusCode { case http.StatusOK, http.StatusCreated, http.StatusNoContent: return res, nil default: resBytes, err := io.ReadAll(res.Body) - if res != nil { - defer res.Body.Close() - } if err != nil { return nil, err } @@ -550,8 +551,8 @@ func (b BranchRep) TotalHunkCount() int { func (b BranchRep) WriteToCSV(outDir, projKey, repo, sha string) (path string, err error) { // Try to create a filename with a shortened sha, but if the sha is too short for some unexpected reason, use the branch name instead var tag string - if len(sha) >= 7 { - tag = sha[:7] + if len(sha) >= shortShaLength { + tag = sha[:shortShaLength] } else { tag = b.Name } @@ -577,7 +578,7 @@ func (b BranchRep) WriteToCSV(outDir, projKey, repo, sha string) (path string, e // sort csv by flag key sort.Slice(records, func(i, j int) bool { // sort by flagKey -> path -> startingLineNumber - for k := 0; k < 3; k++ { + for k := range [3]int{} { if records[i][k] != records[j][k] { return records[i][k] < records[j][k] } diff --git a/options/flags.go b/options/flags.go index adb90ea0..f8a5d4c3 100644 --- a/options/flags.go +++ b/options/flags.go @@ -7,6 +7,11 @@ type flag struct { usage string } +const ( + defaultFlagValue = 2 // Descriptive constant for default flag value + anotherDefaultFlagValue = 10 // Descriptive constant for another default flag value +) + // Options that are available as command line flags var flags = []flag{ { @@ -45,7 +50,7 @@ Allowed template variables: 'branchName', 'sha'. If "commitUrlTemplate" is not p { name: "contextLines", short: "C", - defaultValue: 2, + defaultValue: anotherDefaultFlagValue, usage: `The number of context lines to send to LaunchDarkly. If < 0, no source code will be sent to LaunchDarkly. If 0, only the lines containing flag references will be sent. If > 0, will send that number of context diff --git a/options/options.go b/options/options.go index 4ea891b3..c92dafd4 100644 --- a/options/options.go +++ b/options/options.go @@ -192,7 +192,7 @@ func (o Options) ValidateRequired() error { } if len(o.ProjKey) > 0 && len(o.Projects) > 0 { - return fmt.Errorf("`--projKey` cannot be combined with `projects` in configuration") + return errors.New("`--projKey` cannot be combined with `projects` in configuration") } if len(o.ProjKey) > maxProjKeyLength { @@ -260,7 +260,7 @@ func (o Options) Validate() error { } if o.Revision != "" && o.Branch == "" { - return fmt.Errorf(`"branch" option is required when "revision" option is set`) + return errors.New(`"branch" option is required when "revision" option is set`) } if len(o.Projects) > 0 { diff --git a/search/matcher.go b/search/matcher.go index 765fb13a..be16ca9f 100644 --- a/search/matcher.go +++ b/search/matcher.go @@ -9,6 +9,11 @@ import ( "github.com/launchdarkly/ld-find-code-refs/v2/options" ) +const ( + // ... other constants ... + bufferGrowthFactor = 2 // Descriptive constant for buffer growth +) + type Matcher struct { Elements []ElementMatcher ctxLines int @@ -83,7 +88,7 @@ func buildElementPatterns(flags []string, delimiters string) map[string][]string for _, left := range delimiters { for _, right := range delimiters { var sb strings.Builder - sb.Grow(len(flag) + 2) + sb.Grow(len(flag) + bufferGrowthFactor) sb.WriteRune(left) sb.WriteString(flag) sb.WriteRune(right) From e68f87dbe4b89e14993ee19cd49840a50a07ee9c Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Mon, 16 Dec 2024 14:41:31 -0500 Subject: [PATCH 25/33] more linting --- internal/git/git.go | 7 ++++++- internal/ld/ld.go | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/git/git.go b/internal/git/git.go index 961a5354..db31617a 100644 --- a/internal/git/git.go +++ b/internal/git/git.go @@ -21,6 +21,11 @@ import ( "github.com/launchdarkly/ld-find-code-refs/v2/internal/log" ) +const ( + // ... other constants ... + millisecondsInSecond = 1000 // Descriptive constant for milliseconds conversion +) + type Client struct { workspace string GitBranch string @@ -327,7 +332,7 @@ func makeExtinctionRepFromCommit(projectKey, flagKey string, commit *object.Comm return ld.ExtinctionRep{ Revision: commit.Hash.String(), Message: commit.Message, - Time: commit.Author.When.Unix() * 1000, + Time: commit.Author.When.Unix() * millisecondsInSecond, ProjKey: projectKey, FlagKey: flagKey, } diff --git a/internal/ld/ld.go b/internal/ld/ld.go index 997bf271..9776d4f8 100644 --- a/internal/ld/ld.go +++ b/internal/ld/ld.go @@ -77,8 +77,8 @@ func IsTransient(err error) bool { // Fallback to default backoff if header can't be parsed // https://apidocs.launchdarkly.com/#section/Overview/Rate-limiting // Method is curried in order to avoid stubbing the time package and fallback Backoff in unit tests -func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(minDuration, max time.Duration, attemptNum int, resp *http.Response) time.Duration { - return func(minDuration, max time.Duration, attemptNum int, resp *http.Response) time.Duration { +func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(minDuration, maxDuration time.Duration, attemptNum int, resp *http.Response) time.Duration { + return func(minDuration, maxDuration time.Duration, attemptNum int, resp *http.Response) time.Duration { if resp != nil { if resp.StatusCode == http.StatusTooManyRequests { if s, ok := resp.Header["X-Ratelimit-Reset"]; ok { @@ -96,7 +96,7 @@ func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(minD } } - return fallbackBackoff(minDuration, max, attemptNum, resp) + return fallbackBackoff(minDuration, maxDuration, attemptNum, resp) } } From 1035caeaa5d06c23b5e0b7055b5722224ae1a8ef Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Mon, 16 Dec 2024 14:44:16 -0500 Subject: [PATCH 26/33] more linting --- internal/ld/ld.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/ld/ld.go b/internal/ld/ld.go index 9776d4f8..bc84034d 100644 --- a/internal/ld/ld.go +++ b/internal/ld/ld.go @@ -77,8 +77,8 @@ func IsTransient(err error) bool { // Fallback to default backoff if header can't be parsed // https://apidocs.launchdarkly.com/#section/Overview/Rate-limiting // Method is curried in order to avoid stubbing the time package and fallback Backoff in unit tests -func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(minDuration, maxDuration time.Duration, attemptNum int, resp *http.Response) time.Duration { - return func(minDuration, maxDuration time.Duration, attemptNum int, resp *http.Response) time.Duration { +func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(minDuration, max time.Duration, attemptNum int, resp *http.Response) time.Duration { + return func(minDuration, max time.Duration, attemptNum int, resp *http.Response) time.Duration { if resp != nil { if resp.StatusCode == http.StatusTooManyRequests { if s, ok := resp.Header["X-Ratelimit-Reset"]; ok { @@ -96,7 +96,7 @@ func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(minD } } - return fallbackBackoff(minDuration, maxDuration, attemptNum, resp) + return fallbackBackoff(minDuration, max, attemptNum, resp) } } @@ -193,7 +193,7 @@ func (c ApiClient) getProjectEnvironment(projKey string) (*ldapi.Environment, er } func (c ApiClient) getFlags(projKey string, params url.Values) ([]ldapi.FeatureFlag, error) { - url := c.getPath(fmt.Sprintf("/flags/%s", projKey)) + url := c.getPath("/flags/" + projKey) req, err := h.NewRequest(http.MethodGet, url, nil) if err != nil { return nil, err From 511460a1816c19cdc517f69f6007df04c333a19d Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Mon, 16 Dec 2024 14:47:32 -0500 Subject: [PATCH 27/33] no lint lint issues --- internal/ld/ld.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/ld/ld.go b/internal/ld/ld.go index bc84034d..b919976b 100644 --- a/internal/ld/ld.go +++ b/internal/ld/ld.go @@ -77,8 +77,8 @@ func IsTransient(err error) bool { // Fallback to default backoff if header can't be parsed // https://apidocs.launchdarkly.com/#section/Overview/Rate-limiting // Method is curried in order to avoid stubbing the time package and fallback Backoff in unit tests -func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(minDuration, max time.Duration, attemptNum int, resp *http.Response) time.Duration { - return func(minDuration, max time.Duration, attemptNum int, resp *http.Response) time.Duration { +func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(minDuration, max time.Duration, attemptNum int, resp *http.Response) time.Duration { //nolint:predeclared + return func(minDuration, max time.Duration, attemptNum int, resp *http.Response) time.Duration { //nolint:predeclared if resp != nil { if resp.StatusCode == http.StatusTooManyRequests { if s, ok := resp.Header["X-Ratelimit-Reset"]; ok { @@ -193,7 +193,7 @@ func (c ApiClient) getProjectEnvironment(projKey string) (*ldapi.Environment, er } func (c ApiClient) getFlags(projKey string, params url.Values) ([]ldapi.FeatureFlag, error) { - url := c.getPath("/flags/" + projKey) + url := c.getPath(fmt.Sprintf("/flags/%s", projKey)) req, err := h.NewRequest(http.MethodGet, url, nil) if err != nil { return nil, err From 2eba4b52f6727e9ea1cc15981d0036190f7454d4 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Mon, 16 Dec 2024 14:50:07 -0500 Subject: [PATCH 28/33] lint exceptions --- internal/ld/ld.go | 4 ++-- options/flags.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/ld/ld.go b/internal/ld/ld.go index b919976b..0a5def52 100644 --- a/internal/ld/ld.go +++ b/internal/ld/ld.go @@ -109,7 +109,7 @@ func InitApiClient(options ApiOptions) ApiClient { if options.RetryMax != nil && *options.RetryMax >= 0 { client.RetryMax = *options.RetryMax } - client.Backoff = RateLimitBackoff(time.Now, h.LinearJitterBackoff) + client.Backoff = RateLimitBackoff(time.Now, h.LinearJitterBackoff) //nolint:bodyclose return ApiClient{ httpClient: client, @@ -193,7 +193,7 @@ func (c ApiClient) getProjectEnvironment(projKey string) (*ldapi.Environment, er } func (c ApiClient) getFlags(projKey string, params url.Values) ([]ldapi.FeatureFlag, error) { - url := c.getPath(fmt.Sprintf("/flags/%s", projKey)) + url := c.getPath(fmt.Sprintf("/flags/%s", projKey)) //nolint:perfsprint req, err := h.NewRequest(http.MethodGet, url, nil) if err != nil { return nil, err diff --git a/options/flags.go b/options/flags.go index f8a5d4c3..61fa1a4f 100644 --- a/options/flags.go +++ b/options/flags.go @@ -99,7 +99,7 @@ LaunchDarkly API is unreachable or returns an unexpected response.`, { name: "lookback", short: "l", - defaultValue: 10, + defaultValue: 10, //nolint:gomnd usage: `Sets the number of git commits to search in history for whether a feature flag was removed from code. May be set to 0 to disabled this feature. Setting this option to a high value will increase search time.`, }, From c8694a63c032e9a85361ae7a24114f8b65256f82 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Mon, 16 Dec 2024 14:51:54 -0500 Subject: [PATCH 29/33] no lint --- options/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/flags.go b/options/flags.go index 61fa1a4f..0f4e982e 100644 --- a/options/flags.go +++ b/options/flags.go @@ -99,7 +99,7 @@ LaunchDarkly API is unreachable or returns an unexpected response.`, { name: "lookback", short: "l", - defaultValue: 10, //nolint:gomnd + defaultValue: 10, //nolint:mnd usage: `Sets the number of git commits to search in history for whether a feature flag was removed from code. May be set to 0 to disabled this feature. Setting this option to a high value will increase search time.`, }, From 2dcaa8f5c90ab76576d85eede40ac60e91bfa6b9 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Mon, 16 Dec 2024 14:56:38 -0500 Subject: [PATCH 30/33] formating --- options/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/flags.go b/options/flags.go index 0f4e982e..9158e8ef 100644 --- a/options/flags.go +++ b/options/flags.go @@ -8,7 +8,7 @@ type flag struct { } const ( - defaultFlagValue = 2 // Descriptive constant for default flag value + defaultFlagValue = 2 // Descriptive constant for default flag value anotherDefaultFlagValue = 10 // Descriptive constant for another default flag value ) From 0672bbe8d74bab78d0494f09d713a4fe416d4b3d Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Mon, 16 Dec 2024 14:59:53 -0500 Subject: [PATCH 31/33] more linting --- internal/ld/ld.go | 4 ++-- options/flags.go | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/ld/ld.go b/internal/ld/ld.go index 0a5def52..1f314046 100644 --- a/internal/ld/ld.go +++ b/internal/ld/ld.go @@ -77,8 +77,8 @@ func IsTransient(err error) bool { // Fallback to default backoff if header can't be parsed // https://apidocs.launchdarkly.com/#section/Overview/Rate-limiting // Method is curried in order to avoid stubbing the time package and fallback Backoff in unit tests -func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(minDuration, max time.Duration, attemptNum int, resp *http.Response) time.Duration { //nolint:predeclared - return func(minDuration, max time.Duration, attemptNum int, resp *http.Response) time.Duration { //nolint:predeclared +func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(minDuration, max time.Duration, attemptNum int, resp *http.Response) time.Duration { + return func(minDuration, max time.Duration, attemptNum int, resp *http.Response) time.Duration { if resp != nil { if resp.StatusCode == http.StatusTooManyRequests { if s, ok := resp.Header["X-Ratelimit-Reset"]; ok { diff --git a/options/flags.go b/options/flags.go index 9158e8ef..e91069a2 100644 --- a/options/flags.go +++ b/options/flags.go @@ -8,7 +8,6 @@ type flag struct { } const ( - defaultFlagValue = 2 // Descriptive constant for default flag value anotherDefaultFlagValue = 10 // Descriptive constant for another default flag value ) From 17c632fbdb6e22232b613b55a9fdff7814b89879 Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Mon, 16 Dec 2024 15:03:45 -0500 Subject: [PATCH 32/33] unused param removal / bug --- internal/ld/ld.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/ld/ld.go b/internal/ld/ld.go index 1f314046..dec2eb25 100644 --- a/internal/ld/ld.go +++ b/internal/ld/ld.go @@ -77,8 +77,8 @@ func IsTransient(err error) bool { // Fallback to default backoff if header can't be parsed // https://apidocs.launchdarkly.com/#section/Overview/Rate-limiting // Method is curried in order to avoid stubbing the time package and fallback Backoff in unit tests -func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(minDuration, max time.Duration, attemptNum int, resp *http.Response) time.Duration { - return func(minDuration, max time.Duration, attemptNum int, resp *http.Response) time.Duration { +func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(minDuration, _ time.Duration, attemptNum int, resp *http.Response) time.Duration { + return func(minDuration, max2 time.Duration, attemptNum int, resp *http.Response) time.Duration { if resp != nil { if resp.StatusCode == http.StatusTooManyRequests { if s, ok := resp.Header["X-Ratelimit-Reset"]; ok { @@ -96,7 +96,7 @@ func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(minD } } - return fallbackBackoff(minDuration, max, attemptNum, resp) + return fallbackBackoff(minDuration, max2, attemptNum, resp) } } From 902c9019f15c841106105468533fb94877428a5f Mon Sep 17 00:00:00 2001 From: Kevin Kruger Date: Mon, 16 Dec 2024 15:08:04 -0500 Subject: [PATCH 33/33] do not close request bc test needs it --- internal/ld/ld.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/internal/ld/ld.go b/internal/ld/ld.go index dec2eb25..c1ca4a2b 100644 --- a/internal/ld/ld.go +++ b/internal/ld/ld.go @@ -451,9 +451,6 @@ func (c ApiClient) do(req *h.Request) (*http.Response, error) { return nil, err } - // Ensure the response body is closed - defer res.Body.Close() - // Check for all general status codes returned by the code references API, attempting to deconstruct LD error messages, if possible. switch res.StatusCode { case http.StatusOK, http.StatusCreated, http.StatusNoContent: