-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (31 loc) · 1.11 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
const { Octokit } = require('@octokit/rest');
const config = require('./config.json');
//set values for commit
const commitOwner = config.owner;
const commitRepo = config.repo;
const commitMessage = config.commit_message;
const commitContent = config.file_content;
function randomletters(length) {
let text = '';
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
(async () => {
const octokit = new Octokit({
auth: config.personal_token
});
setInterval(async () => {
await octokit.request('PUT /repos/{owner}/{repo}/contents/{path}', {
owner: commitOwner,
repo: commitRepo,
path: `${randomletters(10)}.txt`,
message: commitMessage,
content: Buffer.from(commitContent).toString('base64')
}).then(res => {
console.log(res.data.commit.url);
}).catch(err => console.log(err));
}, config.interval);
})();