Skip to content

Commit 7d95e61

Browse files
authored
sort by username
1 parent 6b531aa commit 7d95e61

File tree

4 files changed

+48
-21
lines changed

4 files changed

+48
-21
lines changed

src/main.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { IConfig } from './interfaces/IConfig';
1717
const TOKEN_NAME = 'REPO_GITHUB_PAT';
1818
const CONFIG_PATH = 'CONFIG_PATH';
1919

20-
2120
const overwriteBoardIssue = async (issueContents: string, config: IConfig, projectKit: ProjectsOctoKit) => {
2221
const { status } = await projectKit.updateBoardIssue(
2322
config.boardIssue,
@@ -73,7 +72,7 @@ const updateBoardIssue = async (issueContents: string, config: IConfig, projectK
7372
}
7473

7574
const processConfigRecord = async (config: IConfig, projectKit: ProjectsOctoKit) => {
76-
console.log('Processing config: \n', config);
75+
console.log('Processing config: \n', JSON.stringify(config, null, 2));
7776

7877
const validationErrors = validateConfig(config);
7978
if (validationErrors.length) {

src/views/renderIssue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const renderAssignees = (issue: TRepoIssue) => {
6161
const { assignees } = issue;
6262

6363
if (!assignees.length) {
64-
return `❗**unassigned**`;
64+
return `🙋**free issue**`;
6565
}
6666

6767
const users = assignees.map((user) => {

src/views/renderIssuesBlock.ts

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,35 @@ import { TProjectConfig } from '../interfaces/TProjetConfig';
88

99
type TLabeledIssues = Record<string, IWrappedIssue[]>;
1010

11-
const getIssuesForLabel = (label: string, wrappedIssues: IWrappedIssue[]) => {
11+
const NONE_LABEL = 'codespaces-board-undefined-label';
12+
13+
const sortIssuesListByUsername = (issues: IWrappedIssue[]) => {
14+
const result = issues.sort((issue1, issue2) => {
15+
if (!issue1.issue.assignees.length) {
16+
return 1;
17+
}
18+
19+
if (!issue2.issue.assignees.length) {
20+
return -1;
21+
}
22+
23+
if (issue1.issue.assignees[0].login < issue2.issue.assignees[0].login) {
24+
return -1;
25+
}
26+
if (issue1.issue.assignees[0].login > issue2.issue.assignees[0].login) {
27+
return 1;
28+
}
29+
30+
return 0;
31+
});
32+
33+
return result;
34+
};
35+
36+
const getIssuesForLabel = (
37+
label: string,
38+
wrappedIssues: IWrappedIssue[],
39+
): IWrappedIssue[] => {
1240
const result = wrappedIssues.filter(({ issue }) => {
1341
const foundLabel = issue.labels.find((issueLabel) => {
1442
return issueLabel.name === label;
@@ -20,21 +48,21 @@ const getIssuesForLabel = (label: string, wrappedIssues: IWrappedIssue[]) => {
2048
return result;
2149
};
2250

23-
const NONE_LABEL = 'codespaces-board-undefined-label';
24-
2551
const groupIssuesByLabels = (
2652
issues: IWrappedIssue[],
2753
projectConfig: TProjectConfig,
2854
): TLabeledIssues => {
2955
const result: TLabeledIssues = {};
3056

31-
const labels = (typeof projectConfig === 'number')
32-
? []
33-
: projectConfig.trackLabels ?? [];
57+
const labels =
58+
typeof projectConfig === 'number' ? [] : projectConfig.trackLabels ?? [];
3459

3560
const includedIssues = new Set<IWrappedIssue>();
3661
for (let label of labels) {
37-
const issuesForLabel = getIssuesForLabel(label, issues);
62+
const issuesForLabel = sortIssuesListByUsername(
63+
getIssuesForLabel(label, issues),
64+
);
65+
3866
result[label] = issuesForLabel;
3967

4068
for (let issueForLabel of issuesForLabel) {
@@ -63,9 +91,10 @@ const renderIssuesSection = (
6391
) => {
6492
const issueItems = [title];
6593

66-
const isCheckList = (typeof projectConfig === 'number')
67-
? undefined
68-
: projectConfig.isCheckListItems;
94+
const isCheckList =
95+
typeof projectConfig === 'number'
96+
? undefined
97+
: projectConfig.isCheckListItems;
6998

7099
for (let wrappedIssue of issues) {
71100
const { column, issue } = wrappedIssue;
@@ -125,8 +154,7 @@ export const renderIssuesBlock = (
125154
return undefined;
126155
}
127156

128-
return [
129-
renderTitle(title),
130-
renderIssuesList(issues, projectConfig),
131-
].join('\n');
157+
return [renderTitle(title), renderIssuesList(issues, projectConfig)].join(
158+
'\n',
159+
);
132160
};

testConfig2.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
"boardIssue": "https://github.com/legomushroom/codespaces-board/issues/29",
88
"repos": [
99
{
10-
"owner": "legomushroom",
11-
"repo": "codespaces-board",
10+
"owner": "microsoft",
11+
"repo": "vssaas-planning",
1212
"projects": [
1313
{
14-
"id": 1,
15-
"trackLabels": ["port-forwarding", "workbench", "serverless"],
14+
"id": 6,
15+
"trackLabels": ["port-forwarding", "workbench", "serverless", "performance"],
1616
"isCheckListItems": true
1717
}
1818
]

0 commit comments

Comments
 (0)