diff --git a/.github/workflows/secret-scan.yml b/.github/workflows/secret-scan.yml new file mode 100644 index 0000000..85e4fe5 --- /dev/null +++ b/.github/workflows/secret-scan.yml @@ -0,0 +1,10 @@ +name: CB Secret PR Scan + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + SecretScanning: + uses: chargebee/cb-secrets-scanner/.github/workflows/cb-secret-scan.yml@main + secrets: inherit \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..93d4c32 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,5 @@ +repos: + - repo: https://github.com/gitleaks/gitleaks + rev: v8.18.4 + hooks: + - id: gitleaks \ No newline at end of file diff --git a/README.md b/README.md index c1fc5a2..e92e5fc 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ on: types: - opened - closed - - synchronize # See https://mychargebee.atlassian.net/browse/TECHINT-498 + - synchronize branches: - master @@ -50,7 +50,7 @@ jobs: prStatusChange: runs-on: ubuntu-latest steps: - - name: Install Node # See https://github.com/chargebee/chargebee-app/pull/37468 + - name: Install Node uses: actions/setup-node@v3 with: node-version: 18.x diff --git a/apps/github.js b/apps/github.js index 90d7a19..8306a92 100644 --- a/apps/github.js +++ b/apps/github.js @@ -22,6 +22,26 @@ async function setLabels(context, issueNumber, labels) { await context.octokit.issues.setLabels(context.repo({issue_number: issueNumber, labels: labels})) } +async function resolveAllComments(context, prNumber) { + try { + const { data: comments } = await context.octokit.request( + 'GET /repos/{owner}/{repo}/pulls/{pull_number}/comments', + context.repo({pull_number: prNumber}) + ) + + for (const comment of comments) { + if (comment.user.login !== 'cursor[bot]') continue; + console.log("deleting comment : " + comment.id); + await context.octokit.request( + 'DELETE /repos/{owner}/{repo}/pulls/comments/{comment_id}', + context.repo({comment_id: comment.id}) + ); + } + } catch(err) { + console.error(err); + } +} + async function mergePr(context, pr, onMergeFailure) { const maxRetries = 5 let i = 0 @@ -56,6 +76,7 @@ async function isMergeable (context, prNumber) { const maxRetries = 5 let i = 0 while (i++ < maxRetries) { + await resolveAllComments(context, prNumber); const pr = await context.octokit.pulls.get(context.repo({pull_number: prNumber})) console.log(`PR Details of ${prNumber}`) console.log(JSON.stringify(pr.data, null, 2)); diff --git a/dist/index.js b/dist/index.js index ea2de3b..d4e3bb5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -51,6 +51,26 @@ async function setLabels(context, issueNumber, labels) { await context.octokit.issues.setLabels(context.repo({issue_number: issueNumber, labels: labels})) } +async function resolveAllComments(context, prNumber) { + try { + const { data: comments } = await context.octokit.request( + 'GET /repos/{owner}/{repo}/pulls/{pull_number}/comments', + context.repo({pull_number: prNumber}) + ) + + for (const comment of comments) { + if (comment.user.login !== 'cursor[bot]') continue; + console.log("deleting comment : " + comment.id); + await context.octokit.request( + 'DELETE /repos/{owner}/{repo}/pulls/comments/{comment_id}', + context.repo({comment_id: comment.id}) + ); + } + } catch(err) { + console.error(err); + } +} + async function mergePr(context, pr, onMergeFailure) { const maxRetries = 5 let i = 0 @@ -85,6 +105,7 @@ async function isMergeable (context, prNumber) { const maxRetries = 5 let i = 0 while (i++ < maxRetries) { + await resolveAllComments(context, prNumber); const pr = await context.octokit.pulls.get(context.repo({pull_number: prNumber})) console.log(`PR Details of ${prNumber}`) console.log(JSON.stringify(pr.data, null, 2));