Skip to content

Commit

Permalink
make https optional
Browse files Browse the repository at this point in the history
  • Loading branch information
aweis89 committed Dec 1, 2023
1 parent 4267297 commit 5a8db72
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 40 deletions.
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
32 changes: 16 additions & 16 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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* () {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
});
});
}
Expand Down Expand Up @@ -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')}
Expand All @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 24 additions & 24 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -84,7 +89,11 @@ async function setupArgoCDCommand(): Promise<(params: string) => Promise<ExecRes
}

async function getApps(): Promise<App[]> {
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;
Expand All @@ -99,10 +108,11 @@ async function getApps(): Promise<App[]> {
}

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
);
});
}
Expand All @@ -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}
Expand All @@ -137,12 +147,12 @@ ${error.stderr}
${JSON.stringify(error.err)}
\`\`\`
`
: ''
}
: ''
}
${
diff
? `
diff
? `
<details>
\`\`\`diff
Expand All @@ -151,14 +161,14 @@ ${diff}
</details>
`
: ''
}
: ''
}
---
`
);

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')}
Expand All @@ -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,
Expand Down

0 comments on commit 5a8db72

Please sign in to comment.