Skip to content

Commit 1fdd731

Browse files
authored
minor refactor
1 parent 4a66e29 commit 1fdd731

File tree

2 files changed

+83
-54
lines changed

2 files changed

+83
-54
lines changed

src/main.ts

Lines changed: 77 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,78 @@
11
import * as core from '@actions/core'
2-
import { env } from './utils/env';
2+
import {env} from './utils/env'
33

44
// add .env file support
5-
require('dotenv').config();
6-
7-
import { AuthorizationError } from './errors/AuthorizationError';
8-
import { ProjectsOctoKit } from './octokit/ProjectsOctoKit';
9-
import { TEST_CONFIG } from './testConfig';
10-
import { TColumnTypes } from './interfaces/TColumnTypes';
11-
import { IWrappedIssue } from './interfaces/IWrappedIssue';
12-
import { renderIssuesBlock } from './views/renderIssuesBlock';
13-
import { TRepoIssue } from './interfaces/TRepoIssue';
14-
import { TProject } from './interfaces/TProject';
15-
16-
export const OWNER = 'legomushroom';
17-
export const REPO = 'codespaces-board';
18-
const TOKEN_NAME = 'REPO_GITHUB_PAT';
19-
20-
const renderProject = async (projectKit: ProjectsOctoKit, project: TProject): Promise<string> => {
21-
const columns = await projectKit.getColumns(project);
22-
const issues = await projectKit.getRepoIssues(TEST_CONFIG.repos[0]);
23-
const progressIssues = await projectKit.filterIssuesForColumnCards(issues, columns[TColumnTypes.InProgress]);
24-
const doneIssues = await projectKit.filterIssuesForColumnCards(issues, columns[TColumnTypes.Done]);
25-
const backlogIssues = await projectKit.filterIssuesForColumnCards(issues, columns[TColumnTypes.Committed]);
26-
27-
const wrappedProgressIssues: IWrappedIssue[] = progressIssues.map(wrapIssue(TColumnTypes.InProgress));
28-
const wrappedDoneIssues: IWrappedIssue[] = doneIssues.map(wrapIssue(TColumnTypes.Done));
29-
const wrappedIssues = [...wrappedProgressIssues, ...wrappedDoneIssues];
30-
31-
const projectTitle = `### ${project.name}`;
32-
const inWorkIssuesString = renderIssuesBlock(`🏗️ In work (${doneIssues.length}/${progressIssues.length + doneIssues.length})`, wrappedIssues);
33-
34-
const wrappedBacklogIssues: IWrappedIssue[] = backlogIssues.map(wrapIssue(TColumnTypes.Committed));
35-
36-
const backlogIssuesString = renderIssuesBlock(`📅 Backlog (${wrappedBacklogIssues.length})`, wrappedBacklogIssues);
37-
38-
return [
39-
'',
40-
projectTitle,
41-
inWorkIssuesString,
42-
backlogIssuesString,
43-
].join('\n');
5+
require('dotenv').config()
6+
7+
import {AuthorizationError} from './errors/AuthorizationError'
8+
import {ProjectsOctoKit} from './octokit/ProjectsOctoKit'
9+
import {TEST_CONFIG} from './testConfig'
10+
import {TColumnTypes} from './interfaces/TColumnTypes'
11+
import {IWrappedIssue} from './interfaces/IWrappedIssue'
12+
import {renderIssuesBlock} from './views/renderIssuesBlock'
13+
import {TRepoIssue} from './interfaces/TRepoIssue'
14+
import {TProject} from './interfaces/TProject'
15+
import {IRepoSourceConfig} from './interfaces/IRepoSourceConfig'
16+
17+
export const OWNER = 'legomushroom'
18+
export const REPO = 'codespaces-board'
19+
const TOKEN_NAME = 'REPO_GITHUB_PAT'
20+
21+
const renderProject = async (
22+
projectKit: ProjectsOctoKit,
23+
repo: IRepoSourceConfig,
24+
project: TProject
25+
): Promise<string> => {
26+
const columns = await projectKit.getColumns(project)
27+
const issues = await projectKit.getRepoIssues(repo)
28+
const progressIssues = await projectKit.filterIssuesForColumnCards(
29+
issues,
30+
columns[TColumnTypes.InProgress]
31+
)
32+
const doneIssues = await projectKit.filterIssuesForColumnCards(
33+
issues,
34+
columns[TColumnTypes.Done]
35+
)
36+
const backlogIssues = await projectKit.filterIssuesForColumnCards(
37+
issues,
38+
columns[TColumnTypes.Committed]
39+
)
40+
41+
const wrappedProgressIssues: IWrappedIssue[] = progressIssues.map(
42+
wrapIssue(TColumnTypes.InProgress)
43+
)
44+
const wrappedDoneIssues: IWrappedIssue[] = doneIssues.map(
45+
wrapIssue(TColumnTypes.Done)
46+
)
47+
const wrappedIssues = [...wrappedProgressIssues, ...wrappedDoneIssues]
48+
49+
const projectTitle = `### ${project.name}`
50+
const inWorkIssuesString = renderIssuesBlock(
51+
`🏗️ In work (${doneIssues.length}/${
52+
progressIssues.length + doneIssues.length
53+
})`,
54+
wrappedIssues
55+
)
56+
57+
const wrappedBacklogIssues: IWrappedIssue[] = backlogIssues.map(
58+
wrapIssue(TColumnTypes.Committed)
59+
)
60+
61+
const backlogIssuesString = renderIssuesBlock(
62+
`📅 Backlog (${wrappedBacklogIssues.length})`,
63+
wrappedBacklogIssues
64+
)
65+
66+
return ['', projectTitle, inWorkIssuesString, backlogIssuesString].join('\n')
4467
}
4568

4669
const wrapIssue = (column: TColumnTypes) => {
4770
return (issue: TRepoIssue) => {
4871
return {
4972
column,
50-
issue,
51-
};
52-
};
73+
issue
74+
}
75+
}
5376
}
5477

5578
async function run(): Promise<void> {
@@ -61,18 +84,21 @@ async function run(): Promise<void> {
6184
}
6285

6386
const projectKit = new ProjectsOctoKit(token);
64-
const projects = await projectKit.getAllProjects(TEST_CONFIG.repos);
87+
const repoProjects = await projectKit.getAllProjects(TEST_CONFIG.repos);
6588

66-
const result = await Promise.all(projects.map((project) => {
67-
return renderProject(projectKit, project);
68-
}));
69-
70-
console.log(result.join('\n') + '\n');
89+
for (let { repo, projects } of repoProjects ) {
90+
const result = await Promise.all(
91+
projects.map(project => {
92+
return renderProject(projectKit, repo, project)
93+
})
94+
)
7195

96+
console.log(result.join('\n') + '\n');
97+
}
7298
} catch (error) {
7399
console.error(error);
74-
core.setFailed(error.message)
100+
core.setFailed(error.message);
75101
}
76102
}
77103

78-
run();
104+
run()

src/octokit/ProjectsOctoKit.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,18 @@ export class ProjectsOctoKit extends OctoKitBase {
4343

4444
public getAllProjects = async (
4545
repos: IRepoSourceConfig[]
46-
): Promise<TProject[]> => {
46+
): Promise<{ repo: IRepoSourceConfig, projects: TProject[] }[]> => {
4747
const result = []
4848

4949
for (let repo of repos) {
5050
const projects = await this.getRepoProjects(repo)
51-
result.push(...projects)
51+
result.push({
52+
repo,
53+
projects
54+
})
5255
}
5356

54-
return result
57+
return result;
5558
}
5659

5760
public getColumns = async (project: TProject): Promise<TColumnsMap> => {

0 commit comments

Comments
 (0)