-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
45 lines (35 loc) · 1.08 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
// Description:
// Watch Github resources in messages and expands to readable text
//
// Author:
// Christophe Hamerling
const GithubClient = require('github');
const parseUrl = require('parse-github-url');
const repositoryRegexp = new RegExp('(?:git|https?|git@)(?:\\:\\/\\/)?github.com[/|:][A-Za-z0-9-]+?\\/[\\w\\.-]+\\/?(?!=.git)(?:\\.git(?:\\/?|\\#[\\w\\.\\-_]+)?)?$');
const github = new GithubClient({
headers: {
'user-agent': 'hubot-github-expand'
}
});
module.exports = (robot) => {
robot.hear(repositoryRegexp, getRepositoryAsText);
function getRepositoryAsText(res) {
const url = res.match[0].trim();
if (!url) {
return robot.logger.info('no github url found')
}
const parsed = parseUrl(url);
github.repos.get({
owner: parsed.owner,
repo: parsed.name
}, (err, repo) => {
if (err || !repo) {
return robot.logger.error('Can not get repository information', err);
}
res.send(`${repo.full_name}: ${repo.description} - ${repo.stargazers_count} ⭐️`);
});
}
return {
getRepositoryAsText
};
};