Skip to content

Commit

Permalink
Fix matching empty PR description and fail the action on error
Browse files Browse the repository at this point in the history
  • Loading branch information
ukupat committed Aug 10, 2021
1 parent 08ec61a commit 3cf4d21
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
42 changes: 21 additions & 21 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8980,29 +8980,29 @@ const payload = context.payload
const githubToken = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput('github-token', { required: true })
const trelloApiKey = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput('trello-api-key', { required: true })
const trelloAuthToken = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput('trello-auth-token', { required: true })
const trelloListIdPullRequestOpen = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput('trello-list-id-pr-open')
const trelloListIdPullRequestClosed = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput('trello-list-id-pr-closed')
const trelloListIdPrOpen = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput('trello-list-id-pr-open')
const trelloListIdPrClosed = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput('trello-list-id-pr-closed')

async function run(pr) {
const url = pr.html_url || pr.url
const comments = await getPullRequestComments()
const cardIds = await getCardIds(pr.body, comments)

if (cardIds.length) {
console.log('Found card ids', cardIds)

await addAttachmentToCards(cardIds, url)

if (
pr.state === 'open' &&
pr.mergeable_state !== 'draft' &&
trelloListIdPullRequestOpen &&
trelloListIdPullRequestOpen.length > 0
) {
await moveCardsToList(cardIds, trelloListIdPullRequestOpen)
} else if (pr.state === 'closed' && trelloListIdPullRequestClosed && trelloListIdPullRequestClosed.length > 0) {
await moveCardsToList(cardIds, trelloListIdPullRequestClosed)

try {
const comments = await getPullRequestComments()
const cardIds = await getCardIds(pr.body, comments)

if (cardIds.length) {
console.log('Found card ids', cardIds)

await addAttachmentToCards(cardIds, url)

if (pr.state === 'open' && pr.mergeable_state !== 'draft' && trelloListIdPrOpen) {
await moveCardsToList(cardIds, trelloListIdPrOpen)
} else if (pr.state === 'closed' && trelloListIdPrClosed) {
await moveCardsToList(cardIds, trelloListIdPrClosed)
}
}
} catch (error) {
_actions_core__WEBPACK_IMPORTED_MODULE_1__.setFailed(error)
}
}

Expand All @@ -9017,7 +9017,7 @@ async function getCardIds(prBody, comments) {
return cardIds
}

function matchCardIds(text) {
function matchCardIds(text = '') {
const matches = text.match(/(https\:\/\/trello\.com\/c\/(\w+)(\/\S*)?)/g) || []

return matches
Expand Down Expand Up @@ -9048,7 +9048,7 @@ async function addAttachmentToCards(cardIds, link) {
const extantAttachments = await getCardAttachments(cardId)

if (extantAttachments && extantAttachments.some((it) => it.url.includes(link))) {
console.log('Found existing attachment, skipping', cardId, link)
console.log('Found existing attachment, skipping adding attachment', cardId, link)
return
}
console.log('Adding attachment to the card', cardId, link)
Expand Down
42 changes: 21 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ const payload = context.payload
const githubToken = core.getInput('github-token', { required: true })
const trelloApiKey = core.getInput('trello-api-key', { required: true })
const trelloAuthToken = core.getInput('trello-auth-token', { required: true })
const trelloListIdPullRequestOpen = core.getInput('trello-list-id-pr-open')
const trelloListIdPullRequestClosed = core.getInput('trello-list-id-pr-closed')
const trelloListIdPrOpen = core.getInput('trello-list-id-pr-open')
const trelloListIdPrClosed = core.getInput('trello-list-id-pr-closed')

async function run(pr) {
const url = pr.html_url || pr.url
const comments = await getPullRequestComments()
const cardIds = await getCardIds(pr.body, comments)

if (cardIds.length) {
console.log('Found card ids', cardIds)

await addAttachmentToCards(cardIds, url)

if (
pr.state === 'open' &&
pr.mergeable_state !== 'draft' &&
trelloListIdPullRequestOpen &&
trelloListIdPullRequestOpen.length > 0
) {
await moveCardsToList(cardIds, trelloListIdPullRequestOpen)
} else if (pr.state === 'closed' && trelloListIdPullRequestClosed && trelloListIdPullRequestClosed.length > 0) {
await moveCardsToList(cardIds, trelloListIdPullRequestClosed)

try {
const comments = await getPullRequestComments()
const cardIds = await getCardIds(pr.body, comments)

if (cardIds.length) {
console.log('Found card ids', cardIds)

await addAttachmentToCards(cardIds, url)

if (pr.state === 'open' && pr.mergeable_state !== 'draft' && trelloListIdPrOpen) {
await moveCardsToList(cardIds, trelloListIdPrOpen)
} else if (pr.state === 'closed' && trelloListIdPrClosed) {
await moveCardsToList(cardIds, trelloListIdPrClosed)
}
}
} catch (error) {
core.setFailed(error)
}
}

Expand All @@ -45,7 +45,7 @@ async function getCardIds(prBody, comments) {
return cardIds
}

function matchCardIds(text) {
function matchCardIds(text = '') {
const matches = text.match(/(https\:\/\/trello\.com\/c\/(\w+)(\/\S*)?)/g) || []

return matches
Expand Down Expand Up @@ -76,7 +76,7 @@ async function addAttachmentToCards(cardIds, link) {
const extantAttachments = await getCardAttachments(cardId)

if (extantAttachments && extantAttachments.some((it) => it.url.includes(link))) {
console.log('Found existing attachment, skipping', cardId, link)
console.log('Found existing attachment, skipping adding attachment', cardId, link)
return
}
console.log('Adding attachment to the card', cardId, link)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@remato/trello-integration-action",
"version": "3.0.1",
"version": "3.1.1",
"license": "MIT",
"description": "GitHub Action to integrate Github pull requests with Trello cards",
"main": "dist/index.js",
Expand Down

0 comments on commit 3cf4d21

Please sign in to comment.