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

feat: support multiple app deploys in a single PR #484

Merged
Merged
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
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 @@ -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