Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a6b3449

Browse filesBrowse files
authored
Merge pull request #13 from range-labs/dpup/eps
Update dependencies and use new Oktokit constructor
2 parents 6a3b0db + b2262ac commit a6b3449
Copy full SHA for a6b3449

File tree

3 files changed

+50
-45
lines changed
Filter options

3 files changed

+50
-45
lines changed

‎lib/index.js

Copy file name to clipboardExpand all lines: lib/index.js
+42-37Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const crypto = require('crypto');
44
const https = require('https');
55

66
const colors = require('colors');
7-
const octokit = require('@octokit/rest');
7+
const { Octokit } = require('@octokit/rest');
88
const rc = require('rc');
99

1010
const pkg = require('../package.json');
@@ -39,7 +39,7 @@ colors.setTheme(cfg.colors);
3939
validateConfig();
4040

4141
// We use Octokit to access GitHub REST APIS. See https://octokit.github.io/rest.js/ for docs.
42-
const client = octokit({
42+
const client = new Octokit({
4343
userAgent: `github2range/${pkg.version}`,
4444
baseUrl: `https://${cfg.githubHost}`,
4545
auth: cfg.githubAccessToken,
@@ -76,44 +76,49 @@ const eventMappers = {
7676
};
7777

7878
(async () => {
79-
const {
80-
data: { login: username },
81-
} = await client.users.getAuthenticated();
82-
83-
const after = Date.now() - cfg.maxAge * 60 * 60 * 1000;
84-
const afterStr = new Date(after).toLocaleString();
85-
console.log(`▸ Collecting events for ${username} after ${afterStr}`.info);
86-
87-
let events = await listEvents(username, after);
88-
let suggestions = {};
89-
let unmappedUsers = {};
90-
events.forEach((evt) => {
91-
const username = evt.actor.login;
92-
const email = cfg.users[username];
93-
if (!email) {
94-
unmappedUsers[username] = (unmappedUsers[username] || 0) + 1;
95-
return;
96-
}
97-
if (eventMappers[evt.type]) {
98-
const s = eventMappers[evt.type](evt, email);
99-
if (s && !suggestions[s.attachment.source_id]) {
100-
suggestions[s.attachment.source_id] = s;
101-
const a = s.attachment;
102-
console.log(`• Suggestion for ${username} ${a.type} ${s.reason} : ${a.name}`.debug);
79+
try {
80+
const {
81+
data: { login: username },
82+
} = await client.users.getAuthenticated();
83+
84+
const after = Date.now() - cfg.maxAge * 60 * 60 * 1000;
85+
const afterStr = new Date(after).toLocaleString();
86+
console.log(`▸ Collecting events for ${username} after ${afterStr}`.info);
87+
88+
let events = await listEvents(username, after);
89+
let suggestions = {};
90+
let unmappedUsers = {};
91+
events.forEach((evt) => {
92+
const username = evt.actor.login;
93+
const email = cfg.users[username];
94+
if (!email) {
95+
unmappedUsers[username] = (unmappedUsers[username] || 0) + 1;
96+
return;
10397
}
104-
}
105-
});
98+
if (eventMappers[evt.type]) {
99+
const s = eventMappers[evt.type](evt, email);
100+
if (s && !suggestions[s.attachment.source_id]) {
101+
suggestions[s.attachment.source_id] = s;
102+
const a = s.attachment;
103+
console.log(`• Suggestion for ${username} ${a.type} ${s.reason} : ${a.name}`.debug);
104+
}
105+
}
106+
});
106107

107-
const names = Object.keys(unmappedUsers);
108-
if (names.length !== 0) {
109-
console.log(`▸ Saw ${names.length} events from unmapped users: ${names.join(', ')}`.debug);
110-
}
108+
const names = Object.keys(unmappedUsers);
109+
if (names.length !== 0) {
110+
console.log(`▸ Saw ${names.length} events from unmapped users: ${names.join(', ')}`.debug);
111+
}
111112

112-
console.log(`▸ ${Object.values(suggestions).length} suggestions found, sending to Range`.info);
113-
for (let i in suggestions) {
114-
await makeSuggestion(suggestions[i]);
113+
console.log(`▸ ${Object.values(suggestions).length} suggestions found, sending to Range`.info);
114+
for (let i in suggestions) {
115+
await makeSuggestion(suggestions[i]);
116+
}
117+
console.log(`▸ All done!`.warn);
118+
} catch (e) {
119+
console.log(e.message.error);
120+
console.log(e);
115121
}
116-
console.log(`▸ All done!`.warn);
117122
})();
118123

119124
// Fetches events for each org the authenticated user is a member of.
@@ -126,7 +131,7 @@ async function listEvents(username, after) {
126131
let done = false;
127132
try {
128133
while (!done) {
129-
const { data } = await client.activity.listEventsForOrg({
134+
const { data } = await client.activity.listOrgEventsForAuthenticatedUser({
130135
username,
131136
org,
132137
page,

‎package-lock.json

Copy file name to clipboardExpand all lines: package-lock.json
+7-7Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "github2range",
33
"description": "Self-hosted GitHub integration for Range.",
4-
"version": "1.0.2",
4+
"version": "1.0.4",
55
"license": "Apache-2.0",
66
"repository": {
77
"type": "git",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.