Skip to content

Commit

Permalink
Merge branch 'kaisermann-feature/support-multiple-deploy-messages' in…
Browse files Browse the repository at this point in the history
…to develop

* kaisermann-feature/support-multiple-deploy-messages:
  embed SHA256 site ID instead of raw site ID
  feat: support multiple app deploys in a single PR
  • Loading branch information
nwtgck committed Apr 26, 2021
2 parents a67b658 + 4df74db commit 77d584a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
18 changes: 13 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,15 @@ const github_1 = __nccwpck_require__(95438);
const netlify_1 = __importDefault(__nccwpck_require__(44666));
const path = __importStar(__nccwpck_require__(85622));
const inputs_1 = __nccwpck_require__(36180);
const commentIdentifierString = '<!-- NETLIFY DEPLOY COMMENT GENERATED BY ACTIONS_NETLIFY -->';
function findIssueComment(githubClient) {
const crypto = __importStar(__nccwpck_require__(76417));
function getCommentIdentifier(siteId) {
const sha256SiteId = crypto
.createHash('sha256')
.update(siteId)
.digest('hex');
return `<!-- NETLIFY DEPLOY COMMENT GENERATED BY ACTIONS_NETLIFY - APP ID SHA256: ${sha256SiteId} -->`;
}
function findIssueComment(githubClient, siteId) {
return __awaiter(this, void 0, void 0, function* () {
const listCommentsRes = yield githubClient.issues.listComments({
owner: github_1.context.issue.owner,
Expand All @@ -143,9 +150,10 @@ function findIssueComment(githubClient) {
issue_number: github_1.context.issue.number
});
const comments = listCommentsRes.data;
const commentIdentifier = getCommentIdentifier(siteId);
for (const comment of comments) {
// If comment contains the comment identifier
if (comment.body.includes(commentIdentifierString)) {
if (comment.body.includes(commentIdentifier)) {
return comment.id;
}
}
Expand Down Expand Up @@ -228,7 +236,7 @@ function run(inputs) {
if (githubToken === '') {
return;
}
const markdownComment = `${commentIdentifierString}\n${message}`;
const markdownComment = `${getCommentIdentifier(siteId)}\n${message}`;
// Create GitHub client
const githubClient = github_1.getOctokit(githubToken);
if (enableCommitComment) {
Expand Down Expand Up @@ -256,7 +264,7 @@ function run(inputs) {
let commentId = undefined;
if (overwritesPullRequestComment) {
// Find issue comment
commentId = yield findIssueComment(githubClient);
commentId = yield findIssueComment(githubClient, siteId);
}
// NOTE: if not overwrite, commentId is always undefined
if (commentId !== undefined) {
Expand Down
23 changes: 16 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ import {OctokitResponse} from '@octokit/types/dist-types/OctokitResponse'
import NetlifyAPI from 'netlify'
import * as path from 'path'
import {defaultInputs, Inputs} from './inputs'

const commentIdentifierString =
'<!-- NETLIFY DEPLOY COMMENT GENERATED BY ACTIONS_NETLIFY -->'
import * as crypto from 'crypto'

function getCommentIdentifier(siteId: string): string {
const sha256SiteId: string = crypto
.createHash('sha256')
.update(siteId)
.digest('hex')
return `<!-- NETLIFY DEPLOY COMMENT GENERATED BY ACTIONS_NETLIFY - APP ID SHA256: ${sha256SiteId} -->`
}

async function findIssueComment(
githubClient: InstanceType<typeof GitHub>
githubClient: InstanceType<typeof GitHub>,
siteId: string
): Promise<number | undefined> {
const listCommentsRes = await githubClient.issues.listComments({
owner: context.issue.owner,
Expand All @@ -21,9 +28,11 @@ async function findIssueComment(
})

const comments = listCommentsRes.data
const commentIdentifier = getCommentIdentifier(siteId)

for (const comment of comments) {
// If comment contains the comment identifier
if (comment.body.includes(commentIdentifierString)) {
if (comment.body.includes(commentIdentifier)) {
return comment.id
}
}
Expand Down Expand Up @@ -122,7 +131,7 @@ export async function run(inputs: Inputs): Promise<void> {
if (githubToken === '') {
return
}
const markdownComment = `${commentIdentifierString}\n${message}`
const markdownComment = `${getCommentIdentifier(siteId)}\n${message}`

// Create GitHub client
const githubClient = getOctokit(githubToken)
Expand Down Expand Up @@ -152,7 +161,7 @@ export async function run(inputs: Inputs): Promise<void> {
let commentId: number | undefined = undefined
if (overwritesPullRequestComment) {
// Find issue comment
commentId = await findIssueComment(githubClient)
commentId = await findIssueComment(githubClient, siteId)
}

// NOTE: if not overwrite, commentId is always undefined
Expand Down

1 comment on commit 77d584a

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.