-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
485 lines (422 loc) · 11.9 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
#!/usr/bin/env node
"use strict";
const qoa = require("qoa");
const Conf = require("conf");
const fs = require("fs");
const config = new Conf();
config.clear();
// console.log(config.path);
const shields = "https://img.shields.io";
const badgen = "https://badgen.net";
const table_header = `\n| Syntax | Badge |\n| :--- | :----: |`;
var get_badge_text = (provider, path, url, alt) => {
var type = "";
var style = "";
if (config.has("style")) {
style = config.get("style");
}
if (config.has("type")) {
type = config.get("type");
}
if (type === "HTML") {
return `<a href="${url}"><img alt="${alt}" src="${provider}${path}style=${style}"/></a>`;
} else if (type === "MarkDown") {
return `[![${alt}](${provider}${path}style=${style})](${url})`;
}
};
var make_a_row = (val) => {
return "\n| `" + val + "` | " + val + "|";
};
var rating_badges = () => {};
var other_badges = (user, repo) => {
var text = "\n## Other Badges\n";
text += table_header;
var url = `https://github.com/${user}/${repo}`;
var hit_count = get_badge_text(
"http://hits.dwyl.com",
`/${user}/${repo}.svg?`,
url,
"Hit Count"
);
text += make_a_row(hit_count);
return text;
};
var social_badges = (user, repo) => {
var text = "\n## Social Badges\n";
text += table_header;
var url = `https://github.com/${user}/${repo}`;
var followers = get_badge_text(
shields,
`/github/followers/${user}?`,
`https://github.com/${user}?tab=followers`,
"Followers"
);
text += make_a_row(followers);
var forks = get_badge_text(
shields,
`/github/forks/${user}/${repo}?`,
`https://github.com/${user}/${repo}/network/members`,
"Forks"
);
// console.log(forks);
text += make_a_row(forks);
var stars = get_badge_text(
shields,
`/github/stars/${user}/${repo}?`,
`https://github.com/${user}/${repo}/stargazers`,
"Stars"
);
// console.log(stars);
text += make_a_row(stars);
var watchers = get_badge_text(
shields,
`/github/watchers/${user}/${repo}?`,
`https://github.com/${user}/${repo}/watchers`,
"Watchers"
);
// console.log(watchers);
text += make_a_row(watchers);
if (config.has("twitter")) {
if (
config.get("twitter") !== false &&
config.get("twitter.id") !== undefined
) {
var twitter_follow = get_badge_text(
shields,
`/twitter/follow/${config.get("twitter.id")}?logo=twitter&`,
`https://twitter.com/${config.get("twitter.id")}`,
"Twitter Follow"
);
// console.log(twitter_follow);
text += make_a_row(twitter_follow);
}
}
return text;
};
var dependency_badges = (user, repo) => {
var url = `https://github.com/${user}/${repo}/network/dependencies`;
};
var version_badges = (user, repo) => {
var text = "\n## Version Badges\n";
text += table_header;
var url = `https://github.com/${user}/${repo}/releases`;
var version = get_badge_text(
shields,
`/github/v/release/${user}/${repo}?`,
url,
"Release Version"
);
// console.log(version);
text += make_a_row(version);
return text;
};
var ci_cd_badges = (user, repo) => {
var text = "\n## CI/CD Badges\n";
text += table_header;
var url = `https://github.com/${user}/${repo}`;
if (config.get("github") === false || !config.has("github")) {
return (text = "\n## CI/CD Badges\n");
}
var github_workflow = get_badge_text(
shields,
`/github/workflow/status/${user}/${repo}/${config.get(
"github.workflow"
)}?label=${config.get("github.workflow")}&logo=github&`,
url + `/actions?query=workflow:${config.get("github.workflow")}`,
"GitHub Workflow Status"
);
text += make_a_row(github_workflow);
if (
config.has("ci_cd_provider") &&
config.get("ci_cd_provider") === "Travis"
) {
var travis = get_badge_text(
shields,
`/travis/${user}/${repo}?label=Build&logo=travis&`,
url,
"Travis Build"
);
text += make_a_row(travis);
}
return text;
};
var activity_badges = (user, repo) => {
var text = "\n## Activity Badges\n";
text += table_header;
var url = `https://github.com/${user}/${repo}/graphs/commit-activity`;
var commits_per_month = get_badge_text(
shields,
`/github/commit-activity/m/${user}/${repo}?`,
url,
"Commits/month"
);
// console.log(commits_per_month);
text += make_a_row(commits_per_month);
var last_commit = get_badge_text(
shields,
`/github/last-commit/${user}/${repo}?`,
url,
"Last Commit"
);
// console.log(last_commit);
text += make_a_row(last_commit);
var release_date = get_badge_text(
shields,
`/github/release-date/${user}/${repo}?`,
`https://github.com/${user}/${repo}/releases`,
"Last release date"
);
// console.log(release_date);
text += make_a_row(release_date);
var contributors = get_badge_text(
shields,
`/github/contributors/${user}/${repo}?`,
`https://github.com/${user}/${repo}/graphs/contributors`,
"Contributors"
);
// console.log(contributors);
text += make_a_row(contributors);
return text;
};
var license_badges = (user, repo) => {
var text = "\n## License Badges\n";
text += table_header;
var url = `https://github.com/${user}/${repo}/blob/master/LICENSE`;
var license = get_badge_text(
shields,
`/github/license/${user}/${repo}?`,
url,
"License"
);
// console.log(license);
text += make_a_row(license);
return text;
};
var size_badges = (user, repo) => {
var text = "\n## Size Badges\n";
text += table_header;
var url = `https://github.com/${user}/${repo}`;
var repo_size = get_badge_text(
shields,
`/github/repo-size/${user}/${repo}?`,
url,
"Repo Size"
);
// console.log(repo_size);
text += make_a_row(repo_size);
return text;
};
var analysis_badges = (user, repo) => {
var text = "\n## Analysis Badges\n";
text += table_header;
var url = `https://github.com/${user}/${repo}`;
var languages_count = get_badge_text(
shields,
`/github/languages/count/${user}/${repo}?`,
url,
"Language Count"
);
// console.log(languages_count);
text += make_a_row(languages_count);
var top_language = get_badge_text(
shields,
`/github/languages/top/${user}/${repo}?`,
url,
"Top Language"
);
// console.log(top_language);
text += make_a_row(top_language);
if (
config.has("analysis_provider") &&
config.get("analysis_provider") === "CodeClimate"
) {
var codeclimate_maintain_percent = get_badge_text(
shields,
`/codeclimate/maintainability-percentage/${user}/${repo}?`,
url,
"Code Climate maintainability"
);
// console.log(codeclimate_maintain_percent);
text += make_a_row(codeclimate_maintain_percent);
var codeclimate_issues = get_badge_text(
shields,
`/codeclimate/issues/${user}/${repo}?`,
url,
"Code Climate Issues"
);
// console.log(codeclimate_issues);
text += make_a_row(codeclimate_issues);
}
if (
config.has("analysis_provider") &&
config.get("analysis_provider") === "Codacy"
) {
if (
config.has("codacy.project_id") &&
config.get("codacy.project_id") !== ""
) {
var codacy_project_id = config.get("codacy.project_id");
var codacy_grade = get_badge_text(
shields,
`/codacy/grade/${codacy_project_id}?`,
url,
"Codacy Grade"
);
// console.log(codacy_grade);
text += make_a_row(codacy_grade);
}
}
return text;
};
var issues_badges = (user, repo) => {
var text = "\n## Issues Badges\n";
text += table_header;
var url = `https://github.com/${user}/${repo}/issues`;
var issue_raw = get_badge_text(
shields,
`/github/issues-raw/${user}/${repo}?`,
url,
"Github Issues"
);
// console.log(issues_raw);
text += make_a_row(issue_raw);
var issues_closed = get_badge_text(
shields,
`/github/issues-closed/${user}/${repo}?`,
`https://github.com/${user}/${repo}/issues?q=is%3Aissue+is%3Aclosed`,
"Github closed Issues"
);
// console.log(issues_closed);
text += make_a_row(issues_closed);
var pr_raw = get_badge_text(
shields,
`/github/issues-pr-raw/${user}/${repo}?`,
`https://github.com/${user}/${repo}/pulls`,
"Github open PRs"
);
// console.log(pr_raw);
text += make_a_row(pr_raw);
var pr_closed = get_badge_text(
shields,
`/github/issues-pr-closed/${user}/${repo}?`,
`https://github.com/${user}/${repo}/pulls?q=is%3Apr+is%3Aclosed`,
"Github closed PRs"
);
// console.log(pr_closed);
text += make_a_row(pr_closed);
return text;
};
var analyze_inputs = () => {
const write_stream = fs.createWriteStream(
`./autobadge-${config.get("repo")}-${config.get("style")}.md`
);
write_stream.write("# Autobadge\nThis is an auto-generated file\n");
const user = config.get("user");
const repo = config.get("repo");
write_stream.write(license_badges(user, repo));
write_stream.write(social_badges(user, repo));
write_stream.write(size_badges(user, repo));
write_stream.write(issues_badges(user, repo));
write_stream.write(analysis_badges(user, repo));
write_stream.write(activity_badges(user, repo));
write_stream.write(version_badges(user, repo));
write_stream.write(ci_cd_badges(user, repo));
write_stream.write(other_badges(user, repo));
console.log("\x1b[32m", "\nBadges Creation Completed :)");
};
const interactive_mode = async () => {
var user = await qoa.input({
query: "Type your github username:",
handle: "user",
});
config.set(user);
if (!config.has("user") || config.get("user") === "")
throw new Error("Empty user name");
var repo = await qoa.input({ query: "Type your repo name:", handle: "repo" });
config.set(repo);
if (!config.has("repo") || config.get("repo") === "")
throw new Error("Empty repo name");
var style = await qoa.interactive({
query: "Badges style:",
handle: "style",
symbol: ">",
menu: ["flat", "flat-square", "plastic", "social", "for-the-badge"],
});
config.set(style);
var type = await qoa.interactive({
query: "Badges Type:",
handle: "type",
symbol: ">",
menu: ["MarkDown", "HTML"],
});
config.set(type);
var twitter = await qoa.confirm({
query: "Have Twitter Account?",
handle: "twitter",
accept: "y",
deny: "n",
});
config.set(twitter);
if (config.get("twitter") == true) {
var twitter_id = await qoa.input({ query: "Twitter Id:", handle: "id" });
config.set("twitter", twitter_id);
}
var ci_cd = await qoa.confirm({
query: "Want CI/CD status?",
handle: "ci_cd",
accept: "y",
deny: "n",
});
config.set(ci_cd);
if (config.get("ci_cd") === true) {
var ci_cd_provider = await qoa.interactive({
query: "Your CI/CD provider:",
handle: "ci_cd_provider",
symbol: ">",
menu: ["Travis"],
});
config.set(ci_cd_provider);
}
var analysis = await qoa.confirm({
query: "Code Analysis services added?",
handle: "analysis",
accept: "y",
deny: "n",
});
config.set(analysis);
if (config.has("analysis") && config.get("analysis") === true) {
var analysis_provider = await qoa.interactive({
query: "Your Code Analysis provider:",
handle: "analysis_provider",
symbol: ">",
menu: ["CodeClimate", "Codacy"],
});
config.set(analysis_provider);
}
if (
config.has("analysis_provider") &&
config.get("analysis_provider") === "Codacy"
) {
var project_id = await qoa.secure({
query: "Your Codacy Project ID:",
handle: "project_id",
});
config.set("codacy", project_id);
}
var github_workflow = await qoa.confirm({
query: "GitHub Workflow added?",
handle: "github",
accept: "y",
deny: "n",
});
config.set(github_workflow);
if (config.has("github") && config.get("github") === true) {
var workflow_name = await qoa.input({
query: "Enter GitHub Workflow name:",
handle: "workflow",
});
config.set("github", workflow_name);
}
};
interactive_mode().then(analyze_inputs);
// analyze_inputs();