Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Kaisermann feature/support multiple deploy messages #515

Merged
merged 3 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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