Skip to content

Commit

Permalink
feat: support multiple app deploys in a single PR
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisermann committed Mar 25, 2021
1 parent f3a471b commit 1be48eb
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 commentId = getCommentIdentifierString(siteId)

for (const comment of comments) {
// If comment contains the comment identifier
if (comment.body.includes(commentIdentifierString)) {
if (comment.body.includes(commentId)) {
return comment.id
}
}
Expand Down Expand Up @@ -120,7 +124,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 @@ -150,7 +154,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 1be48eb

Please sign in to comment.