Skip to content

Commit 5f13d93

Browse files
authored
Upgrade Octokit authentication to fix deprecation warnings (#1344)
Upgrade @octokit/rest to v17 @octokit/rest v16 uses a format that will be deprecated starting from v17 to construct an Octokit object, and will cause authentication request to fail. Let's upgrade the octokit version to v17 and use the new format so that future upgrades can happen more smoothly.
1 parent 9eb19af commit 5f13d93

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@
4242
"@angular/router": "^13.4.0",
4343
"@apollo/client": "3.3.0",
4444
"@github/markdown-toolbar-element": "^2.1.1",
45-
"@octokit/rest": "^16.37.0",
45+
"@octokit/auth-oauth-user": "^2.1.2",
4646
"@octokit/core": "^4.2.1",
47+
"@octokit/rest": "^17.11.0",
4748
"apollo-angular": "^3.0.1",
4849
"arcsecond": "^4.1.0",
4950
"core-js": "^3.16.4",

src/app/auth/auth.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class AuthComponent implements OnInit, OnDestroy {
8383
throw new Error(data.error);
8484
}
8585
this.authService.storeOAuthAccessToken(data.token);
86-
this.logger.info('AuthComponent: Sucessfully obtained access token');
86+
this.logger.info('AuthComponent: Successfully octained access token');
8787
})
8888
.catch((err) => {
8989
this.logger.info(`AuthComponent: Error in data fetched from access token URL: ${err}`);

src/app/core/services/github.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { SessionData } from '../models/session.model';
3333
import { ERRORCODE_NOT_FOUND, ErrorHandlingService } from './error-handling.service';
3434
import { LoggingService } from './logging.service';
3535
import { GithubRestIssue } from '../models/github/github-rest-issue';
36+
import { createOAuthUserAuth } from '@octokit/auth-oauth-user';
3637

3738
const { Octokit } = require('@octokit/rest');
3839
const CATCHER_ORG = 'CATcher-org';
@@ -72,8 +73,9 @@ export class GithubService {
7273

7374
storeOAuthAccessToken(accessToken: string) {
7475
octokit = new Octokit({
75-
auth() {
76-
return `Token ${accessToken}`;
76+
authStrategy: createOAuthUserAuth,
77+
auth: {
78+
token: accessToken
7779
},
7880
log: {
7981
debug: (message, ...otherInfo) => this.logger.debug('GithubService: ' + message, ...otherInfo),
@@ -439,7 +441,7 @@ export class GithubService {
439441

440442
fetchDataFile(): Observable<{}> {
441443
return from(
442-
octokit.repos.getContents({ owner: MOD_ORG, repo: DATA_REPO, path: 'data.csv', headers: GithubService.IF_NONE_MATCH_EMPTY })
444+
octokit.repos.getContent({ owner: MOD_ORG, repo: DATA_REPO, path: 'data.csv', headers: GithubService.IF_NONE_MATCH_EMPTY })
443445
).pipe(
444446
map((rawData) => {
445447
return { data: atob(rawData['data']['content']) };
@@ -470,7 +472,7 @@ export class GithubService {
470472
*/
471473
fetchSettingsFile(): Observable<SessionData> {
472474
return from(
473-
octokit.repos.getContents({ owner: MOD_ORG, repo: DATA_REPO, path: 'settings.json', headers: GithubService.IF_NONE_MATCH_EMPTY })
475+
octokit.repos.getContent({ owner: MOD_ORG, repo: DATA_REPO, path: 'settings.json', headers: GithubService.IF_NONE_MATCH_EMPTY })
474476
).pipe(
475477
map((rawData) => JSON.parse(atob(rawData['data']['content']))),
476478
catchError((err) => {

0 commit comments

Comments
 (0)