This repository was archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcommits.ts
104 lines (97 loc) · 2.81 KB
/
commits.ts
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
import { flags } from '@oclif/command';
import * as chalk from 'chalk';
import { ApiResponse } from '../api';
import Command, { buildFlags, TableResult } from '../base-command';
export default class Code extends Command {
static description =
'search github commits. https://developer.github.com/v3/search/#search-commits';
static examples = [
`$ ghs commit --repo octocat/Spoon-Knife css
`,
];
static flags = buildFlags(
{
author: flags.string({
description:
'Matches commits authored by a user (based on email settings).',
}),
committer: flags.string({
description:
'Matches commits committed by a user (based on email settings).',
}),
'author-name': flags.string({
description: 'Matches commits by author name.',
}),
'committer-name': flags.string({
description: 'Matches commits by committer name.',
}),
'author-email': flags.string({
description: 'Matches commits by author email.',
}),
'committer-email': flags.string({
description: 'Matches commits by committer email.',
}),
'author-date': flags.string({
description: 'Matches commits by author date range.',
}),
'committer-date': flags.string({
description: 'Matches commits by committer date range.',
}),
merge: flags.boolean({
allowNo: true,
description:
'--merge filters to merge commits, --no-merge filters out merge commits.',
}),
hash: flags.string({
description: 'Matches commits by hash.',
}),
tree: flags.string({
description: 'Matches commits with the specified git tree hash.',
}),
parent: flags.string({
description: 'Matches commits that have a particular parent.',
}),
is: flags.enum({
options: ['public', 'private'],
description: 'Matches public or private repositories.',
}),
user: flags.string({
description:
'Limits searches to a specific user. Use @me for your username.',
}),
org: flags.string({
description: 'Limits searches to a specific organization.',
}),
repo: flags.string({
description: 'Limits searches to a specific repository.',
}),
sort: flags.enum({
char: 's',
options: ['author-date', 'committer-date'],
description:
'The sort field. Can be author-date or committer-date. Default: results are sorted by best match.',
}),
},
['sort'],
);
static args = [...Command.args];
format(data: ApiResponse): TableResult {
const rows = data.items.reduce((acc, item) => {
const message = chalk.bold(item.commit.message);
const ssha = item.sha.substring(0, 7);
const shortenedUrl = item.html_url.replace(item.sha, ssha);
const url = shortenedUrl;
const repo = chalk.cyan(item.repository.name);
acc.push({ message, repo, url });
return acc;
}, []);
return {
rows,
columns: {
repo: {},
message: {},
url: {},
},
};
}
}