From 5a8db727bd34fc6d204d299c27c406a270a236c0 Mon Sep 17 00:00:00 2001 From: Aaron Weisberg Date: Thu, 30 Nov 2023 14:51:48 -0600 Subject: [PATCH] make https optional --- action.yml | 8 ++++++++ dist/index.js | 32 +++++++++++++++---------------- package-lock.json | 20 ++++++++++++++++++++ src/main.ts | 48 +++++++++++++++++++++++------------------------ 4 files changed, 68 insertions(+), 40 deletions(-) diff --git a/action.yml b/action.yml index 2082025..82f762f 100644 --- a/action.yml +++ b/action.yml @@ -19,6 +19,14 @@ inputs: description: Extra arguments to pass to the argocd CLI default: --grpc-web required: false + plaintext: + description: Whether to use HTTPS + default: false + required: false + environment: + description: Name of env to use in the diff title posted to the PR + default: legacy + required: false runs: using: 'node12' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index 3f070f8..b9522f2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1697,7 +1697,12 @@ core.info(githubToken); const ARGOCD_SERVER_URL = core.getInput('argocd-server-url'); const ARGOCD_TOKEN = core.getInput('argocd-token'); const VERSION = core.getInput('argocd-version'); -const EXTRA_CLI_ARGS = core.getInput('argocd-extra-cli-args'); +const ENV = core.getInput('environment'); +const PLAINTEXT = core.getBooleanInput('plaintext'); +let EXTRA_CLI_ARGS = core.getInput('argocd-extra-cli-args'); +if (PLAINTEXT) { + EXTRA_CLI_ARGS += ' --plaintext'; +} const octokit = github.getOctokit(githubToken); function execCommand(command, options = {}) { return __awaiter(this, void 0, void 0, function* () { @@ -1739,7 +1744,11 @@ function setupArgoCDCommand() { } function getApps() { return __awaiter(this, void 0, void 0, function* () { - const url = `https://${ARGOCD_SERVER_URL}/api/v1/applications?fields=items.metadata.name,items.spec.source.path,items.spec.source.repoURL,items.spec.source.targetRevision,items.spec.source.helm,items.spec.source.kustomize,items.status.sync.status`; + let protocol = 'https'; + if (PLAINTEXT) { + protocol = 'http'; + } + const url = `${protocol}://${ARGOCD_SERVER_URL}/api/v1/applications`; core.info(`Fetching apps from: ${url}`); // eslint-disable-next-line @typescript-eslint/no-explicit-any let responseJson; @@ -1754,7 +1763,8 @@ function getApps() { core.error(e); } return responseJson.items.filter(app => { - return (app.spec.source.repoURL.includes(`${github.context.repo.owner}/${github.context.repo.repo}`) && (app.spec.source.targetRevision === 'master' || app.spec.source.targetRevision === 'main')); + let targetPrimary = app.spec.source.targetRevision === 'master' || app.spec.source.targetRevision === 'main'; + return (app.spec.source.repoURL.includes(`${github.context.repo.owner}/${github.context.repo.repo}`) && targetPrimary); }); }); } @@ -1797,7 +1807,7 @@ ${diff} --- `); const output = scrubSecrets(` -## ArgoCD Diff for commit [\`${shortCommitSha}\`](${commitLink}) +## ArgoCD Diff on ${ENV} for commit [\`${shortCommitSha}\`](${commitLink}) _Updated at ${new Date().toLocaleString('en-US', { timeZone: 'America/Los_Angeles' })} PT_ ${diffOutput.join('\n')} @@ -1812,18 +1822,8 @@ _Updated at ${new Date().toLocaleString('en-US', { timeZone: 'America/Los_Angele owner, repo }); - const existingComment = commentsResponse.data.find(d => d.body.includes('ArgoCD Diff for')); - // Existing comments should be updated even if there are no changes this round in order to indicate that - if (existingComment) { - octokit.rest.issues.updateComment({ - owner, - repo, - comment_id: existingComment.id, - body: output - }); - // Only post a new comment when there are changes - } - else if (diffs.length) { + // Only post a new comment when there are changes + if (diffs.length) { octokit.rest.issues.createComment({ issue_number: github.context.issue.number, owner, diff --git a/package-lock.json b/package-lock.json index b3724b6..19f9eb7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3182,6 +3182,19 @@ "integrity": "sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==", "dev": true }, + "node_modules/flow-bin": { + "version": "0.223.0", + "resolved": "https://registry.npmjs.org/flow-bin/-/flow-bin-0.223.0.tgz", + "integrity": "sha512-E+GmTcBTPIRfnX/Dk19zJewX9grxoVQU+RG3Ypd/Os0OkUSOF7K3Sxo2I+8Oz1EpnPMGhnbM4WRAUuY0JaHRsw==", + "dev": true, + "peer": true, + "bin": { + "flow": "cli.js" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", @@ -10917,6 +10930,13 @@ "integrity": "sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==", "dev": true }, + "flow-bin": { + "version": "0.223.0", + "resolved": "https://registry.npmjs.org/flow-bin/-/flow-bin-0.223.0.tgz", + "integrity": "sha512-E+GmTcBTPIRfnX/Dk19zJewX9grxoVQU+RG3Ypd/Os0OkUSOF7K3Sxo2I+8Oz1EpnPMGhnbM4WRAUuY0JaHRsw==", + "dev": true, + "peer": true + }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", diff --git a/src/main.ts b/src/main.ts index 3d15282..d495daa 100644 --- a/src/main.ts +++ b/src/main.ts @@ -36,7 +36,12 @@ core.info(githubToken); const ARGOCD_SERVER_URL = core.getInput('argocd-server-url'); const ARGOCD_TOKEN = core.getInput('argocd-token'); const VERSION = core.getInput('argocd-version'); -const EXTRA_CLI_ARGS = core.getInput('argocd-extra-cli-args'); +const ENV = core.getInput('environment'); +const PLAINTEXT = core.getBooleanInput('plaintext'); +let EXTRA_CLI_ARGS = core.getInput('argocd-extra-cli-args'); +if (PLAINTEXT) { + EXTRA_CLI_ARGS += ' --plaintext'; +} const octokit = github.getOctokit(githubToken); @@ -84,7 +89,11 @@ async function setupArgoCDCommand(): Promise<(params: string) => Promise { - const url = `https://${ARGOCD_SERVER_URL}/api/v1/applications?fields=items.metadata.name,items.spec.source.path,items.spec.source.repoURL,items.spec.source.targetRevision,items.spec.source.helm,items.spec.source.kustomize,items.status.sync.status`; + let protocol = 'https'; + if (PLAINTEXT) { + protocol = 'http'; + } + const url = `${protocol}://${ARGOCD_SERVER_URL}/api/v1/applications`; core.info(`Fetching apps from: ${url}`); // eslint-disable-next-line @typescript-eslint/no-explicit-any let responseJson: any; @@ -99,10 +108,11 @@ async function getApps(): Promise { } return (responseJson.items as App[]).filter(app => { + let targetPrimary = app.spec.source.targetRevision === 'master' || app.spec.source.targetRevision === 'main' return ( app.spec.source.repoURL.includes( `${github.context.repo.owner}/${github.context.repo.repo}` - ) && (app.spec.source.targetRevision === 'master' || app.spec.source.targetRevision === 'main') + ) && targetPrimary ); }); } @@ -125,8 +135,8 @@ App: [\`${app.metadata.name}\`](https://${ARGOCD_SERVER_URL}/applications/${app. YAML generation: ${error ? ' Error 🛑' : 'Success 🟢'} App sync status: ${app.status.sync.status === 'Synced' ? 'Synced ✅' : 'Out of Sync ⚠️ '} ${ - error - ? ` + error + ? ` **\`stderr:\`** \`\`\` ${error.stderr} @@ -137,12 +147,12 @@ ${error.stderr} ${JSON.stringify(error.err)} \`\`\` ` - : '' -} + : '' + } ${ - diff - ? ` + diff + ? `
\`\`\`diff @@ -151,14 +161,14 @@ ${diff}
` - : '' -} + : '' + } --- ` ); const output = scrubSecrets(` -## ArgoCD Diff for commit [\`${shortCommitSha}\`](${commitLink}) +## ArgoCD Diff on ${ENV} for commit [\`${shortCommitSha}\`](${commitLink}) _Updated at ${new Date().toLocaleString('en-US', { timeZone: 'America/Los_Angeles' })} PT_ ${diffOutput.join('\n')} @@ -175,18 +185,8 @@ _Updated at ${new Date().toLocaleString('en-US', { timeZone: 'America/Los_Angele repo }); - const existingComment = commentsResponse.data.find(d => d.body!.includes('ArgoCD Diff for')); - - // Existing comments should be updated even if there are no changes this round in order to indicate that - if (existingComment) { - octokit.rest.issues.updateComment({ - owner, - repo, - comment_id: existingComment.id, - body: output - }); - // Only post a new comment when there are changes - } else if (diffs.length) { + // Only post a new comment when there are changes + if (diffs.length) { octokit.rest.issues.createComment({ issue_number: github.context.issue.number, owner,