-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
49 lines (46 loc) · 1.55 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
46
47
48
49
const fs = require('fs');
const core = require('@actions/core');
const homeDir = require('os').homedir();
async function run() {
const clientID = core.getInput('client-id');
const clientSecret = core.getInput('client-secret');
const refreshToken = core.getInput('refresh-token');
const claspJSON = getClaspJSON(clientID, clientSecret, refreshToken);
try{
fs.writeFile(require('path').join(homeDir,'.clasprc.json'),JSON.stringify(claspJSON), error => {
if(error) core.setFailed(error.message);
})
}catch(error) {
core.setFailed(error.message);
}
}
function getClaspJSON(clientID, clientSecret, refreshToken) {
const claspJSON = {
token: {
access_token: "",
scope: "https://www.googleapis.com/auth/script.projects https://www.googleapis.com/auth/drive.metadata.readonly https://www.googleapis.com/auth/logging.read https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/script.webapp.deploy https://www.googleapis.com/auth/script.deployments https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/service.management",
token_type: "Bearer",
expiry_date: 0,
refresh_token: ""
},
oauth2ClientSettings: {
clientId: "",
clientSecret: "",
redirectUri: "http://localhost"
},
isLocalCreds: false
}
return {
...claspJSON,
token: {
...claspJSON.token,
refresh_token: refreshToken
},
oauth2ClientSettings: {
...claspJSON.oauth2ClientSettings,
clientId: clientID,
clientSecret,
}
}
}
run();