-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.gs
88 lines (68 loc) · 2.22 KB
/
ui.gs
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// add custom menu
/* function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Custom GitHub Menu')
.addItem('Get User Repos','getUserRepos')
.addItem('Get rate quota','getGitHubRateLimit')
.addToUi();
}
/***************************************/
// Get User Repos
/*function getUserRepos() {
var service = getGithubService_();
if (service.hasAccess()) {
Logger.log("App has access.");
var api = "https://api.github.com/users/benlcollins"; // example
var headers = {
"Authorization": "Bearer " + getGithubService_().getAccessToken(),
"Accept": "application/vnd.github.v3+json"
};
var options = {
"headers": headers,
"method" : "GET",
"muteHttpExceptions": true
};
var response = UrlFetchApp.fetch(api, options);
var json = JSON.parse(response.getContentText());
Logger.log(json); // example
}
else {
Logger.log("App has no access yet.");
// open this url to gain authorization from github
var authorizationUrl = service.getAuthorizationUrl();
Logger.log("Open the following URL and re-run the script: %s",
authorizationUrl);
}
}
/***************************************/
// Get Rate limit
/*function getGitHubRateLimit() {
// set up the service
var service = getGithubService_();
if (service.hasAccess()) {
Logger.log("App has access.");
var api = "https://api.github.com/rate_limit";
var headers = {
"Authorization": "Bearer " + getGithubService_().getAccessToken(),
"Accept": "application/vnd.github.v3+json"
};
var options = {
"headers": headers,
"method" : "GET",
"muteHttpExceptions": true
};
var response = UrlFetchApp.fetch(api, options);
var json = JSON.parse(response.getContentText());
var responseCode = response.getResponseCode();
Logger.log(responseCode);
Logger.log("You have " + json.rate.remaining + " requests left this hour.");
}
else {
Logger.log("App has no access yet.");
// open this url to gain authorization from github
var authorizationUrl = service.getAuthorizationUrl();
Logger.log("Open the following URL and re-run the script: %s",
authorizationUrl);
}
}
*/