|
1 | 1 | /** |
2 | | - * Copyright 2016 Google Inc. All Rights Reserved. |
| 2 | + * Copyright 2018 Google LLC |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
6 | 6 | * You may obtain a copy of the License at |
7 | 7 | * |
8 | | - * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
9 | 9 | * |
10 | 10 | * Unless required by applicable law or agreed to in writing, software |
11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
@@ -55,28 +55,25 @@ function signOut() { |
55 | 55 | * Gets the user's GitHub profile. |
56 | 56 | */ |
57 | 57 | function getGitHubProfile() { |
58 | | - var service = getGitHubService(); |
59 | | - if (!service.hasAccess()) { |
60 | | - throw new Error('Error: Missing GitHub authorization.'); |
61 | | - } |
62 | | - var url = 'https://api.github.com/user'; |
63 | | - var response = UrlFetchApp.fetch(url, { |
64 | | - headers: { |
65 | | - Authorization: 'Bearer ' + service.getAccessToken() |
66 | | - } |
67 | | - }); |
68 | | - return JSON.parse(response.getContentText()); |
| 58 | + return getGitHubResource('user'); |
69 | 59 | } |
70 | 60 |
|
71 | 61 | /** |
72 | 62 | * Gets the user's GitHub repos. |
73 | 63 | */ |
74 | 64 | function getGitHubRepos() { |
| 65 | + return getGitHubResource('user/repos'); |
| 66 | +} |
| 67 | + |
| 68 | +/** |
| 69 | + * Fetches the specified resource from the GitHub API. |
| 70 | + */ |
| 71 | +function getGitHubResource(resource) { |
75 | 72 | var service = getGitHubService(); |
76 | 73 | if (!service.hasAccess()) { |
77 | 74 | throw new Error('Error: Missing GitHub authorization.'); |
78 | 75 | } |
79 | | - var url = 'https://api.github.com/user/repos'; |
| 76 | + var url = 'https://api.github.com/' + resource; |
80 | 77 | var response = UrlFetchApp.fetch(url, { |
81 | 78 | headers: { |
82 | 79 | Authorization: 'Bearer ' + service.getAccessToken() |
|
0 commit comments