1
- import * as core from '@actions/core'
2
- import { env } from './utils/env'
1
+ import * as core from '@actions/core' ;
2
+ import { env } from './utils/env' ;
3
3
4
4
// add .env file support for dev purposes
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'
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
20
21
21
const renderProject = async (
22
22
projectKit : ProjectsOctoKit ,
23
23
repo : IRepoSourceConfig ,
24
- project : TProject
24
+ project : TProject ,
25
25
) : Promise < string > => {
26
- const columns = await projectKit . getColumns ( project )
27
- const issues = await projectKit . getRepoIssues ( repo )
26
+ const columns = await projectKit . getColumns ( project ) ;
27
+ const issues = await projectKit . getRepoIssues ( repo ) ;
28
+
29
+ const backlogIssues = await projectKit . filterIssuesForColumnCards (
30
+ issues ,
31
+ columns ,
32
+ TColumnTypes . Backlog ,
33
+ ) ;
34
+
35
+ const committedIssues = await projectKit . filterIssuesForColumnCards (
36
+ issues ,
37
+ columns ,
38
+ TColumnTypes . Committed ,
39
+ ) ;
40
+
41
+ const blockedIssues = await projectKit . filterIssuesForColumnCards (
42
+ issues ,
43
+ columns ,
44
+ TColumnTypes . Blocked ,
45
+ ) ;
46
+
28
47
const progressIssues = await projectKit . filterIssuesForColumnCards (
29
48
issues ,
30
- columns [ TColumnTypes . InProgress ]
31
- )
32
- const doneIssues = await projectKit . filterIssuesForColumnCards (
49
+ columns ,
50
+ TColumnTypes . InProgress ,
51
+ ) ;
52
+
53
+ const inReviewIssues = await projectKit . filterIssuesForColumnCards (
33
54
issues ,
34
- columns [ TColumnTypes . Done ]
35
- )
36
- const backlogIssues = await projectKit . filterIssuesForColumnCards (
55
+ columns ,
56
+ TColumnTypes . InReview ,
57
+ ) ;
58
+
59
+ const waitingToDeployIssues = await projectKit . filterIssuesForColumnCards (
37
60
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' )
67
- }
61
+ columns ,
62
+ TColumnTypes . WaitingToDeploy ,
63
+ ) ;
68
64
69
- const wrapIssue = ( column : TColumnTypes ) => {
70
- return ( issue : TRepoIssue ) => {
71
- return {
72
- column,
73
- issue
74
- }
75
- }
76
- }
65
+ const doneIssues = await projectKit . filterIssuesForColumnCards (
66
+ issues ,
67
+ columns ,
68
+ TColumnTypes . Done ,
69
+ ) ;
70
+
71
+ const inWorkIssues = [ ...progressIssues , ...inReviewIssues ] ;
72
+ const doneOrDeployIssues = [ ...waitingToDeployIssues , ...doneIssues ] ;
73
+ const allPlannedIssues = [ ...blockedIssues , ...committedIssues , ...inWorkIssues , ...doneOrDeployIssues ] ;
74
+
75
+ const doneRate = doneOrDeployIssues . length / allPlannedIssues . length ;
76
+ const inWorkRate = inWorkIssues . length / allPlannedIssues . length ;
77
+ const committedRate = committedIssues . length / allPlannedIssues . length ;
78
+
79
+ const donePercent = Math . round ( 100 * doneRate ) ;
80
+ const inWorkPercent = Math . round ( 100 * inWorkRate ) ;
81
+ const committedPercent = Math . round ( 100 * committedRate ) ;
82
+
83
+ const blockedIssuesString = renderIssuesBlock (
84
+ `⚠️ ${ blockedIssues . length } Blocked` ,
85
+ blockedIssues ,
86
+ false ,
87
+ ) ;
88
+
89
+ const inWorkCount = `${ inWorkIssues . length } /${ allPlannedIssues . length } ` ;
90
+ const inWorkIssuesString = renderIssuesBlock (
91
+ `🏃 ${ inWorkCount } In work (${ inWorkPercent } %)` ,
92
+ inWorkIssues ,
93
+ ) ;
94
+
95
+ const committedIssuesString = renderIssuesBlock (
96
+ `💪 ${ committedIssues . length } Committed (${ committedPercent } %)` ,
97
+ committedIssues ,
98
+ ) ;
99
+
100
+ const doneCount = `${ doneOrDeployIssues . length } /${ allPlannedIssues . length } ` ;
101
+ const doneIssuesString = renderIssuesBlock (
102
+ `✅ ${ doneCount } Done (${ donePercent } %)` ,
103
+ doneOrDeployIssues ,
104
+ ) ;
105
+
106
+ const projectTitle = `## ${ project . name } - ${ donePercent } % done` ;
107
+ const projectLink = `Link: [${ project . name } ](${ project . html_url } )` ;
108
+ const backlogIssuesCountString = `\n*Backlog: ${ backlogIssues . length } issues*`
109
+
110
+ return [
111
+ '' ,
112
+ projectTitle ,
113
+ projectLink ,
114
+ blockedIssuesString ,
115
+ committedIssuesString ,
116
+ inWorkIssuesString ,
117
+ doneIssuesString ,
118
+ backlogIssuesCountString ,
119
+ ] . join ( '\n' ) ;
120
+ } ;
77
121
78
122
async function run ( ) : Promise < void > {
79
123
try {
@@ -86,12 +130,12 @@ async function run(): Promise<void> {
86
130
const projectKit = new ProjectsOctoKit ( token ) ;
87
131
const repoProjects = await projectKit . getAllProjects ( TEST_CONFIG . repos ) ;
88
132
89
- for ( let { repo, projects } of repoProjects ) {
133
+ for ( let { repo, projects } of repoProjects ) {
90
134
const result = await Promise . all (
91
- projects . map ( project => {
92
- return renderProject ( projectKit , repo , project )
93
- } )
94
- )
135
+ projects . map ( ( project ) => {
136
+ return renderProject ( projectKit , repo , project ) ;
137
+ } ) ,
138
+ ) ;
95
139
96
140
const issueBody = result . join ( '\n' ) + '\n' ;
97
141
@@ -105,24 +149,25 @@ async function run(): Promise<void> {
105
149
footer = await projectKit . getBoardHeaderText ( TEST_CONFIG . footerFileUrl ) ;
106
150
}
107
151
108
- const issueContents = [
109
- header ,
110
- issueBody ,
111
- footer ,
112
- ] . join ( '\n' ) ;
152
+ const issueContents = [ header , issueBody , footer ] . join ( '\n' ) ;
113
153
114
- const { status } = await projectKit . updateBoardIssue ( TEST_CONFIG . boardIssue , issueContents ) ;
154
+ const { status } = await projectKit . updateBoardIssue (
155
+ TEST_CONFIG . boardIssue ,
156
+ issueContents ,
157
+ ) ;
115
158
116
159
if ( status !== 200 ) {
117
- throw new Error ( `Failed to update the issue ${ TEST_CONFIG . boardIssue } .` ) ;
160
+ throw new Error (
161
+ `Failed to update the issue ${ TEST_CONFIG . boardIssue } ` ,
162
+ ) ;
118
163
}
119
164
120
- console . log ( `Successfully updated the board issue. ` ) ;
165
+ console . log ( `Successfully updated the board issue ${ TEST_CONFIG . boardIssue } ` ) ;
121
166
}
122
167
} catch ( error ) {
123
168
console . error ( error ) ;
124
169
core . setFailed ( error . message ) ;
125
170
}
126
171
}
127
172
128
- run ( )
173
+ run ( ) ;
0 commit comments