Skip to content

Commit

Permalink
Send PR number instead of Build number
Browse files Browse the repository at this point in the history
  • Loading branch information
cbartlett committed Oct 2, 2022
1 parent a0141d0 commit 4aace16
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ try {
function moveCardWhenPullRequestClose(apiKey, apiToken) {
const exitLists = JSON.parse(process.env.TRELLO_DEPARTURE_LISTS_ID);
const destinationListId = process.env['TRELLO_DESTINATION_LIST_ID'];
const buildNumber = process.env['GITHUB_RUN_NUMBER'];
const prNumber = process.env['GITHUB_PR_NUMBER'];
const body = github.context.payload.pull_request.body
const title = github.context.payload.pull_request.title
const littlestring = ' ';
const bigstring = title + littlestring + body;
const start = async () => {
const listOfIds = unique(Array.from(matchAll(bigstring, /#(\d+)/g).toArray(), m => +m));

if (listOfIds.length == 0) return;

let cards = [];

for (item of exitLists) {
const newCards = await getCardsOfList(apiKey, apiToken, item);
cards = [...cards, ...newCards];
}

cards
.filter(card => listOfIds.includes(card.idShort))
.forEach(card => {
putCard(apiKey, apiToken, card.id, destinationListId);
addBuildComment(apiKey, apiToken, card.id, buildNumber);
addPRComment(apiKey, apiToken, card.id, prNumber);
});
}
start();
start();
}

function getCardsOfList(apiKey, apiToken, listId) {
Expand Down Expand Up @@ -77,10 +77,10 @@ function putCard(apiKey, apiToken, cardId, destinationListId) {
});
}

function addBuildComment(apiKey, apiToken, cardId, buildNumber) {
function addPRComment(apiKey, apiToken, cardId, prNumber) {
const options = {
method: 'POST',
url: `https://api.trello.com/1/cards/${cardId}/actions/comments?key=${apiKey}&token=${apiToken}&text=Build number: ${buildNumber}`,
url: `https://api.trello.com/1/cards/${cardId}/actions/comments?key=${apiKey}&token=${apiToken}&text=PR number: ${prNumber}`,
}
return new Promise(function(resolve, reject) {
request(options)
Expand All @@ -91,4 +91,4 @@ function addBuildComment(apiKey, apiToken, cardId, buildNumber) {
reject(error);
})
});
}
}

0 comments on commit 4aace16

Please sign in to comment.