Skip to content

Commit

Permalink
Merge branch 'feature/support-multiple-deploy-messages' of https://gi…
Browse files Browse the repository at this point in the history
…thub.com/kaisermann/actions-netlify into kaisermann-feature/support-multiple-deploy-messages
  • Loading branch information
nwtgck committed Apr 26, 2021
2 parents a67b658 + c05bc27 commit a01ea2e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main.ts
Expand Up @@ -7,11 +7,13 @@ import NetlifyAPI from 'netlify'
import * as path from 'path'
import {defaultInputs, Inputs} from './inputs'

const commentIdentifierString =
'<!-- NETLIFY DEPLOY COMMENT GENERATED BY ACTIONS_NETLIFY -->'
function getCommentIdentifierString(siteId: string): string {
return `<!-- NETLIFY DEPLOY COMMENT GENERATED BY ACTIONS_NETLIFY - APP ID: ${siteId} -->`
}

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 +23,11 @@ async function findIssueComment(
})

const comments = listCommentsRes.data
const commentIdString = getCommentIdentifierString(siteId)

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

// Create GitHub client
const githubClient = getOctokit(githubToken)
Expand Down Expand Up @@ -152,7 +156,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

0 comments on commit a01ea2e

Please sign in to comment.