@@ -4,7 +4,6 @@ import { handleAnalytics } from './handle-analytics.mts'
4
4
import constants from '../../constants.mts'
5
5
import { commonFlags , outputFlags } from '../../flags.mts'
6
6
import { checkCommandInput } from '../../utils/check-input.mts'
7
- import { isTestingV1 } from '../../utils/config.mts'
8
7
import { getOutputKind } from '../../utils/get-output-kind.mts'
9
8
import { meowOrExit } from '../../utils/meow-with-subcommands.mts'
10
9
import { getFlagListOutput } from '../../utils/output-formatting.mts'
@@ -23,58 +22,32 @@ const config: CliCommandConfig = {
23
22
...outputFlags ,
24
23
file : {
25
24
type : 'string' ,
26
- shortFlag : 'f' ,
27
- description :
28
- 'Filepath to save output when given. Only valid with --json/--markdown.' ,
29
- } ,
30
- repo : {
31
- type : 'string' ,
32
- shortFlag : 'r' ,
33
- default : '' ,
34
- description : 'Name of the repository. Only valid when scope=repo' ,
35
- } ,
36
- scope : {
37
- type : 'string' ,
38
- shortFlag : 's' ,
39
- default : 'org' ,
40
- description :
41
- "Scope of the analytics data - either 'org' or 'repo', default: org" ,
42
- } ,
43
- time : {
44
- type : 'number' ,
45
- shortFlag : 't' ,
46
- default : 30 ,
47
- description : 'Time filter - either 7, 30 or 90, default: 30' ,
25
+ description : 'Path to store result, only valid with --json/--markdown' ,
48
26
} ,
49
27
} ,
50
28
help : ( command , { flags } ) =>
51
29
`
52
30
Usage
53
- $ ${ command } ${ isTestingV1 ( ) ? '[ org | repo <reponame>] [time]' : '--scope=<scope> --time=<time filter>' }
31
+ $ ${ command } [options] [ " org" | " repo" <reponame>] [TIME]
54
32
55
33
API Token Requirements
56
34
- Quota: 1 unit
57
35
- Permissions: report:write
58
36
59
- ${ isTestingV1 ( ) ? '' : 'Default parameters are set to show the organization-level analytics over the' }
60
- ${ isTestingV1 ( ) ? '' : 'last 30 days.' }
61
-
62
- ${ isTestingV1 ( ) ? 'The scope is either org or repo level, defaults to org.' : '' }
37
+ The scope is either org or repo level, defaults to org.
63
38
64
- ${ isTestingV1 ( ) ? ' When scope is repo, a repo slug must be given as well.' : '' }
39
+ When scope is repo, a repo slug must be given as well.
65
40
66
- ${ isTestingV1 ( ) ? ' The time argument must be number 7, 30, or 90 and defaults to 30.' : '' }
41
+ The TIME argument must be number 7, 30, or 90 and defaults to 30.
67
42
68
43
Options
69
44
${ getFlagListOutput ( flags , 6 ) }
70
45
71
46
Examples
72
- $ ${ command } ${ isTestingV1 ( ) ? 'org 7' : '--scope=org --time=7' }
73
- $ ${ command } ${ isTestingV1 ( ) ? 'repo test-repo 30' : '--scope=org --time=30' }
74
- $ ${ command } ${ isTestingV1 ( ) ? '90' : '--scope=repo --repo=test-repo --time=30' }
75
- `
76
- // Drop consecutive empty lines. Temporarily necessary to deal with v1 prep.
77
- . replace ( / \n (?: * \n ) + / g, '\n\n' ) ,
47
+ $ ${ command } org 7
48
+ $ ${ command } repo test-repo 30
49
+ $ ${ command } 90
50
+ ` ,
78
51
}
79
52
80
53
export const cmdAnalytics = {
@@ -98,7 +71,7 @@ async function run(
98
71
const { file, json, markdown } = cli . flags
99
72
const outputKind = getOutputKind ( json , markdown )
100
73
101
- // In v1 mode support :
74
+ // Supported inputs :
102
75
// - [] (no args)
103
76
// - ['org']
104
77
// - ['org', '30']
@@ -107,84 +80,59 @@ async function run(
107
80
// - ['30']
108
81
// Validate final values in the next step
109
82
let scope = 'org'
110
- let time = isTestingV1 ( ) ? '30' : 30
83
+ let time = '30'
111
84
let repoName = ''
112
- if ( isTestingV1 ( ) ) {
113
- if ( cli . input [ 0 ] === 'org' ) {
114
- if ( cli . input [ 1 ] ) {
115
- time = cli . input [ 1 ]
116
- }
117
- } else if ( cli . input [ 0 ] === 'repo' ) {
118
- scope = 'repo'
119
- if ( cli . input [ 1 ] ) {
120
- repoName = cli . input [ 1 ]
121
- }
122
- if ( cli . input [ 2 ] ) {
123
- time = cli . input [ 2 ]
124
- }
125
- } else if ( cli . input [ 0 ] ) {
126
- time = cli . input [ 0 ]
85
+ if ( cli . input [ 0 ] === 'org' ) {
86
+ if ( cli . input [ 1 ] ) {
87
+ time = cli . input [ 1 ]
127
88
}
128
- } else {
129
- if ( cli . flags [ 'scope' ] ) {
130
- scope = String ( cli . flags [ 'scope' ] || '' )
89
+ } else if ( cli . input [ 0 ] === 'repo' ) {
90
+ scope = 'repo'
91
+ if ( cli . input [ 1 ] ) {
92
+ repoName = cli . input [ 1 ]
131
93
}
132
- if ( scope === 'repo' ) {
133
- repoName = String ( cli . flags [ 'repo' ] || '' )
134
- }
135
- if ( cli . flags [ 'time' ] ) {
136
- time = Number ( cli . flags [ 'time' ] || 30 )
94
+ if ( cli . input [ 2 ] ) {
95
+ time = cli . input [ 2 ]
137
96
}
97
+ } else if ( cli . input [ 0 ] ) {
98
+ time = cli . input [ 0 ]
138
99
}
139
100
140
101
const hasApiToken = hasDefaultToken ( )
141
102
103
+ const noLegacy =
104
+ ! cli . flags [ 'scope' ] && ! cli . flags [ 'repo' ] && ! cli . flags [ 'time' ]
105
+
142
106
const wasValidInput = checkCommandInput (
143
107
outputKind ,
144
- {
145
- // In v1 this can't go wrong anymore since the unknown value goes to time
146
- nook : ! isTestingV1 ( ) ,
147
- test : scope === 'org' || scope === 'repo' ,
148
- message : 'Scope must be "repo" or "org"' ,
149
- pass : 'ok' ,
150
- fail : 'bad' ,
151
- } ,
152
108
{
153
109
nook : true ,
154
- // Before v1 there were no args, only flags
155
- test : isTestingV1 ( ) || cli . input . length === 0 ,
156
- message : 'This command does not accept any arguments (use flags instead)' ,
110
+ test : noLegacy ,
111
+ message : 'Legacy flags are no longer supported. See v1 migration guide.' ,
157
112
pass : 'ok' ,
158
- fail : `bad ` ,
113
+ fail : `received legacy flags ` ,
159
114
} ,
160
115
{
161
116
nook : true ,
162
117
test : scope === 'org' || ! ! repoName ,
163
- message : isTestingV1 ( )
164
- ? 'When scope=repo, repo name should be the second argument'
165
- : 'When scope=repo, repo name should be set through --repo' ,
118
+ message : 'When scope=repo, repo name should be the second argument' ,
166
119
pass : 'ok' ,
167
120
fail : 'missing' ,
168
121
} ,
169
122
{
170
123
nook : true ,
171
124
test :
172
125
scope === 'org' ||
173
- ! isTestingV1 ( ) ||
174
126
( repoName !== '7' && repoName !== '30' && repoName !== '90' ) ,
175
127
message : 'When scope is repo, the second arg should be repo, not time' ,
176
128
pass : 'ok' ,
177
129
fail : 'missing' ,
178
130
} ,
179
131
{
180
- test : isTestingV1 ( )
181
- ? time === '7' || time === '30' || time === '90'
182
- : time === 7 || time === 30 || time === 90 ,
132
+ test : time === '7' || time === '30' || time === '90' ,
183
133
message : 'The time filter must either be 7, 30 or 90' ,
184
134
pass : 'ok' ,
185
- fail : isTestingV1 ( )
186
- ? 'invalid range set, see --help for command arg details.'
187
- : 'bad' ,
135
+ fail : 'invalid range set, see --help for command arg details.' ,
188
136
} ,
189
137
{
190
138
nook : true ,
@@ -222,8 +170,7 @@ async function run(
222
170
223
171
return await handleAnalytics ( {
224
172
scope,
225
- time :
226
- time === '90' || time === 90 ? 90 : time === '30' || time === 30 ? 30 : 7 ,
173
+ time : time === '90' ? 90 : time === '30' ? 30 : 7 ,
227
174
repo : repoName ,
228
175
outputKind,
229
176
filePath : String ( file || '' ) ,
0 commit comments