-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgardener.js
More file actions
88 lines (79 loc) Β· 2.62 KB
/
gardener.js
File metadata and controls
88 lines (79 loc) Β· 2.62 KB
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
const GitHubClient = require('./githubClient');
class gardener {
constructor({githubClient, owner, repo, branch = 'master', messages}) {
this.githubClient = githubClient;
this.owner = owner;
this.repo = repo;
this.branch = branch;
this.messages = messages || [
"π±π±π±π±π±π±π±π±π±π±π±π±π±π±π±π±π±π±π±π±π±π±π±π±π±π±π±π±π±",
"I need to mow the lawn.",
"What, did I ruin the lawn?",
"He gets busy picking weeds and tending to the lawn.",
"Let's meet at the public lawn tomorrow.",
"After finishing it, I'll start on the lawn.",
"But if I water the lawn, the grass will grow.",
"We hired a man to mow the lawn.",
"The lawn in the front yard is kept very neat.",
"Did you cut my lawn a few weeks ago?",
"Do not put off lawn treatment.",
"Our lawn will be mowed twice a month.",
"I want my lawn mower back.",
"I'm trying to do my lawn!",
"I'm gonna check the lawn again.",
"The lawn was checkered with sunlight and shade.",
"The gardener trim the lawn evenly.",
"Your lawn looks fantastic.",
"Let me know about your lawns."
];
}
getRandomMessage() {
return this.messages[Math.floor(Math.random() * this.messages.length)];
}
async get_master() {
this.commit_sha = await this.githubClient.getBranch(
this.owner,
this.repo,
this.branch
);
}
async get_tree() {
this.tree = await this.githubClient.getTree(
this.owner,
this.repo,
this.commit_sha
);
}
async create_tree() {
this.new_tree_sha = await this.githubClient.createTree(
this.owner,
this.repo,
this.tree
);
}
async create_commit() {
this.new_commit_sha = await this.githubClient.createCommit(
this.owner,
this.repo,
this.getRandomMessage(),
this.new_tree_sha
);
}
async update_reference() {
return await this.githubClient.updateReference(
this.owner,
this.repo,
this.branch,
this.new_commit_sha,
false
);
}
async run() {
await this.get_master();
await this.get_tree();
await this.create_tree();
await this.create_commit();
await this.update_reference();
}
}
module.exports = gardener;