Skip to content

Commit 159f76a

Browse files
committed
fix(git-node): remove code duplication in security.js
1 parent 5034b4f commit 159f76a

File tree

1 file changed

+23
-40
lines changed

1 file changed

+23
-40
lines changed

components/git/security.js

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -92,110 +92,93 @@ export function builder(yargs) {
9292
}
9393

9494
export function handler(argv) {
95+
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
96+
const cli = new CLI(logStream);
97+
9598
if (argv.start) {
96-
return startSecurityRelease(argv);
99+
return startSecurityRelease(cli, argv);
97100
}
98101
if (argv.sync) {
99-
return syncSecurityRelease(argv);
102+
return syncSecurityRelease(cli, argv);
100103
}
101104
if (argv['update-date']) {
102-
return updateReleaseDate(argv);
105+
return updateReleaseDate(cli, argv);
103106
}
104107
if (argv['pre-release']) {
105-
return createPreRelease(argv);
108+
return createPreRelease(cli, argv);
106109
}
107110
if (argv['add-report']) {
108-
return addReport(argv);
111+
return addReport(cli, argv);
109112
}
110113
if (argv['remove-report']) {
111-
return removeReport(argv);
114+
return removeReport(cli, argv);
112115
}
113116
if (argv['notify-pre-release']) {
114-
return notifyPreRelease(argv);
117+
return notifyPreRelease(cli, argv);
115118
}
116119
if (argv['request-cve']) {
117-
return requestCVEs(argv);
120+
return requestCVEs(cli, argv);
118121
}
119122
if (argv['post-release']) {
120-
return createPostRelease(argv);
123+
return createPostRelease(cli, argv);
121124
}
122125
if (argv.cleanup) {
123-
return cleanupSecurityRelease(argv);
126+
return cleanupSecurityRelease(cli, argv);
124127
}
125128
yargsInstance.showHelp();
126129
}
127130

128-
async function removeReport(argv) {
131+
async function removeReport(cli, argv) {
129132
const reportId = argv['remove-report'];
130-
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
131-
const cli = new CLI(logStream);
132133
const update = new UpdateSecurityRelease(cli);
133134
return update.removeReport(reportId);
134135
}
135136

136-
async function addReport(argv) {
137+
async function addReport(cli, argv) {
137138
const reportId = argv['add-report'];
138-
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
139-
const cli = new CLI(logStream);
140139
const update = new UpdateSecurityRelease(cli);
141140
return update.addReport(reportId);
142141
}
143142

144-
async function updateReleaseDate(argv) {
143+
async function updateReleaseDate(cli, argv) {
145144
const releaseDate = argv['update-date'];
146-
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
147-
const cli = new CLI(logStream);
148145
const update = new UpdateSecurityRelease(cli);
149146
return update.updateReleaseDate(releaseDate);
150147
}
151148

152-
async function createPreRelease(argv) {
149+
async function createPreRelease(cli, argv) {
153150
const nodejsOrgFolder = argv['pre-release'];
154-
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
155-
const cli = new CLI(logStream);
156151
const preRelease = new SecurityBlog(cli);
157152
return preRelease.createPreRelease(nodejsOrgFolder);
158153
}
159154

160-
async function requestCVEs() {
161-
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
162-
const cli = new CLI(logStream);
155+
async function requestCVEs(cli) {
163156
const hackerOneCve = new UpdateSecurityRelease(cli);
164157
return hackerOneCve.requestCVEs();
165158
}
166159

167-
async function createPostRelease(argv) {
160+
async function createPostRelease(cli, argv) {
168161
const nodejsOrgFolder = argv['post-release'];
169-
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
170-
const cli = new CLI(logStream);
171162
const blog = new SecurityBlog(cli);
172163
return blog.createPostRelease(nodejsOrgFolder);
173164
}
174165

175-
async function startSecurityRelease() {
176-
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
177-
const cli = new CLI(logStream);
166+
async function startSecurityRelease(cli) {
178167
const release = new PrepareSecurityRelease(cli);
179168
return release.start();
180169
}
181170

182-
async function cleanupSecurityRelease() {
183-
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
184-
const cli = new CLI(logStream);
171+
async function cleanupSecurityRelease(cli) {
185172
const release = new PrepareSecurityRelease(cli);
186173
return release.cleanup();
187174
}
188175

189-
async function syncSecurityRelease(argv) {
190-
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
191-
const cli = new CLI(logStream);
176+
async function syncSecurityRelease(cli) {
192177
const release = new UpdateSecurityRelease(cli);
193178
return release.sync();
194179
}
195180

196-
async function notifyPreRelease() {
197-
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
198-
const cli = new CLI(logStream);
181+
async function notifyPreRelease(cli) {
199182
const preRelease = new SecurityAnnouncement(cli);
200183
return preRelease.notifyPreRelease();
201184
}

0 commit comments

Comments
 (0)