Skip to content

Commit

Permalink
fix: make card action optional (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
andybardagi authored Aug 11, 2024
1 parent 7e59b85 commit c5a2ae9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34467,7 +34467,7 @@ async function getMultipleCardIdsFromBranchName(conf, branchName) {
async function isCardAlreadyLinked(cardIds, shortId) {
return cardIds.some(async (cardId) => {
const card = await (0, trello_1.getCardInfo)(cardId);
return card.actions.some((action) => action.data.card.idShort === parseInt(shortId));
return card.actions?.some((action) => action.data.card.idShort === parseInt(shortId)) ?? false;
});
}
/**
Expand All @@ -34492,7 +34492,7 @@ async function getTrelloCardByTitle(title, shortId) {
.sort((a, b) => new Date(b.dateLastActivity).getTime() - new Date(a.dateLastActivity).getTime())
.map((card) => (0, trello_1.getCardInfo)(card.id)));
return cards.find((card) => card.idShort === parseInt(shortId) ||
card.actions.some((action) => action.data.card.idShort === parseInt(shortId)))?.shortLink;
(card.actions?.some((action) => action.data.card.idShort === parseInt(shortId)) ?? false))?.shortLink;
}
/**
* Creates a new card when user has written "/new-trello-card" to the PR description
Expand Down
6 changes: 3 additions & 3 deletions src/actions/getCardIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ async function getMultipleCardIdsFromBranchName(conf: Conf, branchName: string)
}
}

async function isCardAlreadyLinked(cardIds: string[], shortId: string) {
async function isCardAlreadyLinked(cardIds: string[], shortId: string): Promise<boolean> {
return cardIds.some(async (cardId) => {
const card = await getCardInfo(cardId)

return card.actions.some((action) => action.data.card.idShort === parseInt(shortId))
return card.actions?.some((action) => action.data.card.idShort === parseInt(shortId)) ?? false
})
}

Expand Down Expand Up @@ -174,7 +174,7 @@ async function getTrelloCardByTitle(title: string, shortId: string) {
return cards.find(
(card) =>
card.idShort === parseInt(shortId) ||
card.actions.some((action) => action.data.card.idShort === parseInt(shortId)),
(card.actions?.some((action) => action.data.card.idShort === parseInt(shortId)) ?? false),
)?.shortLink
}

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export type Card = {
url: string
shortUrl: string
shortLink: string
actions: {
actions?: {
data: {
card: {
idShort: number
Expand Down

0 comments on commit c5a2ae9

Please sign in to comment.