-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerged_prs.js
48 lines (44 loc) · 1.09 KB
/
merged_prs.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
const alfy = require('alfy');
const { query } = require('./graphql');
const { getRelativeTime } = require('./date');
const graphql = `{
search(
first: 20,
type: ISSUE,
query: "is:pr is:merged author:${process.env.USERNAME} archived:false sort:updated-desc"
) {
nodes {
... on PullRequest {
number
title
repository {
nameWithOwner
}
url
mergedAt
}
}
}
}`;
const filter = (item, input) => {
const title = item.title.toLowerCase();
const nameWithOwner = item.repository.nameWithOwner.toLowerCase();
return title.includes(input) || nameWithOwner.includes(input);
};
const map = (o) => {
const mergedAt = getRelativeTime(o.mergedAt);
const subtitle = `${o.repository.nameWithOwner}: #${o.number} merged ${mergedAt}`;
return {
title: o.title,
subtitle,
arg: o.url,
};
};
module.exports = async (searchInput) => {
const { search } = await query(graphql);
let rawData = search.nodes;
if (searchInput) {
rawData = alfy.matches(searchInput, rawData, filter);
}
return rawData.map(map);
};