Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit 84c8338

Browse files
committed
Merge branch 'main' into releases/v2
2 parents 756e059 + d21a1e9 commit 84c8338

4 files changed

Lines changed: 29 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
mirror_column:
3636
runs-on: ubuntu-latest
3737
steps:
38-
- uses: jonabc/linked-project-columns@v1
38+
- uses: jonabc/linked-project-columns@v2
3939
with:
4040
source_column_id: <column node id>
4141
target_column_id: <column node id>

dist/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6223,10 +6223,14 @@ async function ensureCardAtIndex(column, toIndex, findCardFunc, newCardFunc) {
62236223
if (!card) {
62246224
// add card to remote project column cards
62256225
card = await api.addCardToColumn(column, newCardFunc());
6226-
currentIndex = 0;
62276226

6228-
// add the card to the local column cards
6229-
column.cards.nodes.splice(0, 0, card);
6227+
// add card to local project column cards if API was successful
6228+
if (card) {
6229+
currentIndex = 0;
6230+
6231+
// add the card to the local column cards
6232+
column.cards.nodes.splice(0, 0, card);
6233+
}
62306234
}
62316235

62326236
if (card && currentIndex !== toIndex) {

src/linked-project-columns.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ async function ensureCardAtIndex(column, toIndex, findCardFunc, newCardFunc) {
2626
if (!card) {
2727
// add card to remote project column cards
2828
card = await api.addCardToColumn(column, newCardFunc());
29-
currentIndex = 0;
3029

31-
// add the card to the local column cards
32-
column.cards.nodes.splice(0, 0, card);
30+
// add card to local project column cards if API was successful
31+
if (card) {
32+
currentIndex = 0;
33+
34+
// add the card to the local column cards
35+
column.cards.nodes.splice(0, 0, card);
36+
}
3337
}
3438

3539
if (card && currentIndex !== toIndex) {

test/linked-project-columns.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,20 @@ describe('linked-project-columns', () => {
207207
expect(api.moveCardToIndex.getCall(0).args).toEqual([targetColumn, 0, 1]);
208208
});
209209

210+
it('does not add a card to the local target column when the remote call fails', async () => {
211+
sourceColumns[0].cards.nodes.push({ id: 1, note: '1' });
212+
// when the remote call fails, addCardToColumn returns null. overwrite
213+
// the default method stub to return null.
214+
api.addCardToColumn.returns(null);
215+
216+
await run();
217+
expect(targetColumn.cards.nodes).toEqual([]);
218+
219+
expect(api.addCardToColumn.callCount).toEqual(1);
220+
expect(api.addCardToColumn.getCall(0).args).toEqual([targetColumn, { id: 1, note: '1' }]);
221+
expect(api.moveCardToIndex.callCount).toEqual(0);
222+
});
223+
210224
it('moves cards on the target to match the source', async () => {
211225
sourceColumns[0].cards.nodes.push({ id: 1, note: '1' }, { id: 2, note: '2' });
212226
targetColumn.cards.nodes.push({ id: 202, note: '2' }, { id: 201, note: '1' });

0 commit comments

Comments
 (0)