Skip to content

Commit 6c855d2

Browse files
authored
add the new items cutoff setting
1 parent bf94adb commit 6c855d2

File tree

7 files changed

+57
-16
lines changed

7 files changed

+57
-16
lines changed

dist/index.js

Lines changed: 20 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schemas/IConfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@
112112
"items": {
113113
"type": "string"
114114
}
115+
},
116+
"newCardsCutoffDays": {
117+
"description": "How many days should elapse since the beginning of\nthe sprint for a card to be treated as `new`.",
118+
"type": "number"
115119
}
116120
},
117121
"additionalProperties": false,

src/interfaces/IProject.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,10 @@ export interface IProject {
4343
* the assigned GitHub issues.
4444
*/
4545
developers?: string[];
46+
47+
/**
48+
* How many days should elapse since the beginning of
49+
* the sprint for a card to be treated as `new`.
50+
*/
51+
newCardsCutoffDays?: number;
4652
}

src/octokit/ProjectsOctoKit.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ export class ProjectsOctoKit extends OctoKitBase {
264264
columns: TColumnsWithCardsMap,
265265
columnType: TColumnTypes,
266266
config: IConfig,
267+
project: IProjectWithConfig,
267268
): ICardWithIssue[] => {
268269
// get the column
269270
const column = columns[columnType];
@@ -283,7 +284,7 @@ export class ProjectsOctoKit extends OctoKitBase {
283284
card,
284285
issue: cardIssue,
285286
column: columnType,
286-
isNew: isNewCard(card, config),
287+
isNew: isNewCard(card, config, project),
287288
}
288289
});
289290

src/utils/getProjectData.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const getProjectData = async (
3636
cards,
3737
TColumnTypes.Backlog,
3838
config,
39+
project,
3940
);
4041
console.log(`BacklogIssues: ${backlogIssues.length} items`);
4142

@@ -44,6 +45,7 @@ export const getProjectData = async (
4445
cards,
4546
TColumnTypes.Committed,
4647
config,
48+
project,
4749
);
4850
console.log(`CommittedIssues: ${committedIssues.length} items`);
4951

@@ -52,6 +54,7 @@ export const getProjectData = async (
5254
cards,
5355
TColumnTypes.Blocked,
5456
config,
57+
project,
5558
);
5659
console.log(`BlockedIssues: ${blockedIssues.length} items`);
5760

@@ -60,6 +63,7 @@ export const getProjectData = async (
6063
cards,
6164
TColumnTypes.InProgress,
6265
config,
66+
project,
6367
);
6468
console.log(`ProgressIssues: ${progressIssues.length} items`);
6569

@@ -68,6 +72,7 @@ export const getProjectData = async (
6872
cards,
6973
TColumnTypes.InReview,
7074
config,
75+
project,
7176
);
7277
console.log(`InReviewIssues: ${inReviewIssues.length} items`);
7378

@@ -76,6 +81,7 @@ export const getProjectData = async (
7681
cards,
7782
TColumnTypes.WaitingToDeploy,
7883
config,
84+
project,
7985
);
8086
console.log(`WaitingToDeployIssues: ${waitingToDeployIssues.length} items`);
8187

@@ -84,6 +90,7 @@ export const getProjectData = async (
8490
cards,
8591
TColumnTypes.Done,
8692
config,
93+
project,
8794
);
8895
console.log(`doneIssues: ${doneIssues.length} items`);
8996

src/utils/isNewCard.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
import { ICardWithIssue } from '../interfaces/ICardWithIssue';
21
import { IConfig } from '../interfaces/IConfig';
2+
import { IProjectWithConfig } from '../interfaces/IProjectWithConfig';
33
import { TColumnCard } from '../interfaces/TColumnCard';
44

5+
const dateAddDays = (startDate: Date, days: number) => {
6+
const date = new Date();
7+
date.setDate(startDate.getDate() + days);
8+
9+
return date;
10+
};
11+
512
/**
613
* Check if card is a new - was created after
714
* the sprint start date.
815
*/
916
export const isNewCard = (
1017
card: TColumnCard,
11-
config: IConfig
18+
config: IConfig,
19+
projectWithConfig: IProjectWithConfig,
1220
): boolean => {
1321
const { sprintStartDate: sprintStartDateString } = config;
1422

@@ -19,5 +27,11 @@ export const isNewCard = (
1927
const cardCreationDate = new Date(card.created_at);
2028
const sprintStartDate = new Date(sprintStartDateString);
2129

22-
return cardCreationDate.getTime() >= sprintStartDate.getTime();
30+
const { projectConfig } = projectWithConfig;
31+
32+
const newCardsCutoffDays = (typeof projectConfig === 'number' || !projectConfig.newCardsCutoffDays)
33+
? 0
34+
: projectConfig.newCardsCutoffDays;
35+
36+
return cardCreationDate.getTime() >= dateAddDays(sprintStartDate, newCardsCutoffDays).getTime();
2337
};

0 commit comments

Comments
 (0)