Skip to content

Commit d8d82ce

Browse files
committed
Update folder structure
1 parent 7875e4a commit d8d82ce

8 files changed

Lines changed: 47 additions & 53 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import axios from "axios";
22
import { Err, Ok, Result } from "ts-results";
33
import dotenv from "dotenv";
4-
import githubDiscordMap from "../../data/githubDiscordMap.json";
5-
import { Item } from "../items";
4+
import githubDiscordMap from "../../../data/githubDiscordMap.json";
5+
import { Item } from "../../items";
66

77
dotenv.config();
88

File renamed without changes.
File renamed without changes.
Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import axios from "axios";
22
import { Ok, Err, Result } from "ts-results";
33
import dotenv from "dotenv";
44
import { PROJECT_V2_ITEMS } from "./graphql";
5+
import { Item } from "../../items";
56

67
dotenv.config();
78

@@ -36,15 +37,16 @@ export interface ProjectV2Item {
3637
};
3738
}
3839

39-
export const fetchProjectV2Items = async (): Promise<
40-
Result<ProjectV2Item[], Error>
41-
> => {
40+
export const fetchProjectV2Items = async (): Promise<Result<Item[], Error>> => {
4241
const result = await fetchData();
4342
if (result.err) {
4443
return result;
4544
}
4645

47-
return Ok(result.val.data.organization.projectV2.items.nodes);
46+
const formattedItems = convertGithubItems(
47+
result.val.data.organization.projectV2.items.nodes,
48+
);
49+
return Ok(formattedItems);
4850
};
4951

5052
const TOKEN = process.env.GITHUB_ACCESS_TOKEN ?? "";
@@ -67,3 +69,33 @@ const fetchData = async (): Promise<Result<any, Error>> => {
6769
return Err(new Error("Failed to fetch data"));
6870
}
6971
};
72+
73+
const convertGithubItems = (items: ProjectV2Item[]) => {
74+
return items.map((item: ProjectV2Item) => {
75+
const assignedUsers = item.fieldValues.nodes
76+
.filter((field) => field.users)
77+
.flatMap((field) => field.users.nodes.map((user) => user.url));
78+
const status = item.fieldValues.nodes
79+
.filter((field) => field.name)
80+
.map((field) => field.name)[0];
81+
const labels = item.fieldValues.nodes
82+
.filter((field) => field.labels)
83+
.flatMap((field) => field.labels.nodes.map((label) => label.name));
84+
85+
// TODO: improve this
86+
let dueDate: Date | undefined;
87+
if (item.fieldValueByName?.date) {
88+
dueDate = new Date(item.fieldValueByName.date);
89+
dueDate.setDate(dueDate.getDate() + 1);
90+
}
91+
92+
return {
93+
title: item.content.title,
94+
url: item.content.url,
95+
assignedUsers,
96+
labels,
97+
dueDate: dueDate,
98+
status: status,
99+
};
100+
});
101+
};

src/items/index.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { ProjectV2Item } from "../github";
2-
31
export interface Item {
42
title: string;
53
status: string;
@@ -9,36 +7,6 @@ export interface Item {
97
url?: string;
108
}
119

12-
export const convertGithubItems = (items: ProjectV2Item[]): Item[] => {
13-
return items.map((item: ProjectV2Item) => {
14-
const assignedUsers = item.fieldValues.nodes
15-
.filter((field) => field.users)
16-
.flatMap((field) => field.users.nodes.map((user) => user.url));
17-
const status = item.fieldValues.nodes
18-
.filter((field) => field.name)
19-
.map((field) => field.name)[0];
20-
const labels = item.fieldValues.nodes
21-
.filter((field) => field.labels)
22-
.flatMap((field) => field.labels.nodes.map((label) => label.name));
23-
24-
// TODO: improve this
25-
let dueDate: Date | undefined;
26-
if (item.fieldValueByName?.date) {
27-
dueDate = new Date(item.fieldValueByName.date);
28-
dueDate.setDate(dueDate.getDate() + 1);
29-
}
30-
31-
return {
32-
title: item.content.title,
33-
url: item.content.url,
34-
assignedUsers,
35-
labels,
36-
dueDate: dueDate,
37-
status: status,
38-
};
39-
});
40-
};
41-
4210
export const filterByDateRange = (
4311
items: Item[],
4412
startDate: Date,

src/reminders/dueTodayReminder.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { sendDiscordItemMessage } from "../discord";
2-
import { fetchProjectV2Items } from "../github";
1+
import { sendDiscordItemMessage } from "../infrastructure/discord";
2+
import { fetchProjectV2Items } from "../infrastructure/github";
33
import {
4-
convertGithubItems,
54
filterForUnassigned,
65
filterForUrgentItems,
76
filterOutStatus,
@@ -13,8 +12,7 @@ export const dueTodayReminder = async () => {
1312
return githubItemsResult;
1413
}
1514

16-
const items = convertGithubItems(githubItemsResult.val);
17-
const nonBacklogItems = filterOutStatus(items, "Backlog");
15+
const nonBacklogItems = filterOutStatus(githubItemsResult.val, "Backlog");
1816
const unassignedItems = filterForUnassigned(nonBacklogItems);
1917
const urgentItems = filterForUrgentItems(nonBacklogItems);
2018

src/reminders/fullItemReportReminder.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { sendDiscordItemMessage } from "../discord";
2-
import { fetchProjectV2Items } from "../github";
1+
import { sendDiscordItemMessage } from "../infrastructure/discord";
2+
import { fetchProjectV2Items } from "../infrastructure/github";
33
import {
4-
convertGithubItems,
54
filterForUnassigned,
65
filterForUrgentItems,
76
filterOutStatus,
@@ -14,8 +13,7 @@ export const fullItemReportReminder = async () => {
1413
return githubItemsResult;
1514
}
1615

17-
const items = convertGithubItems(githubItemsResult.val);
18-
const nonBacklogItems = filterOutStatus(items, "Backlog");
16+
const nonBacklogItems = filterOutStatus(githubItemsResult.val, "Backlog");
1917
const unassignedItems = filterForUnassigned(nonBacklogItems);
2018
const upcomingItems = filterUpcomingItems(nonBacklogItems);
2119
const urgentItems = filterForUrgentItems(nonBacklogItems);

src/reminders/urgentPromotionReminder.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { sendDiscordItemMessage } from "../discord";
2-
import { fetchProjectV2Items } from "../github";
1+
import { sendDiscordItemMessage } from "../infrastructure/discord";
2+
import { fetchProjectV2Items } from "../infrastructure/github";
33
import {
4-
convertGithubItems,
54
filterByLabel,
65
filterForTwentyFourHours,
76
filterOutStatus,
@@ -13,8 +12,7 @@ export const urgentPromotionReminder = async () => {
1312
return githubItemsResult;
1413
}
1514

16-
const items = convertGithubItems(githubItemsResult.val);
17-
const nonBacklogItems = filterOutStatus(items, "Backlog");
15+
const nonBacklogItems = filterOutStatus(githubItemsResult.val, "Backlog");
1816
const urgentItems = filterForTwentyFourHours(nonBacklogItems);
1917
const itemsWithLabels = filterByLabel(urgentItems, [
2018
"discord announcement",

0 commit comments

Comments
 (0)