-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathlib.test.w
More file actions
81 lines (66 loc) · 2.05 KB
/
Copy pathlib.test.w
File metadata and controls
81 lines (66 loc) · 2.05 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
bring util;
bring fs;
bring cloud;
bring "./lib.w" as probot;
let handler = inflight (ctx) => {
let repo = ctx.payload.repository;
// find all changed mdfiles by comparing the commits of the PR
let compare = ctx.octokit.repos.compareCommits(
owner: repo.owner.login,
repo: repo.name,
base: ctx.payload.pull_request.base.sha,
head: ctx.payload.pull_request.head.sha,
);
let mdFiles = MutMap<str>{};
for commit in compare.data.commits {
let commitContent = ctx.octokit.repos.getCommit(
owner: repo.owner.login,
repo: repo.name,
ref: ctx.payload.pull_request.head.ref,
);
if let files = commitContent.data.files {
for file in files {
if file.filename.endsWith(".md") &&
(file.status == "modified" || file.status == "added" || file.status == "changed") {
mdFiles.set(file.filename, file.sha);
}
}
}
}
// list over mdfiles and update them
for filename in mdFiles.keys() {
let contents = ctx.octokit.repos.getContent(
owner: repo.owner.login,
repo: repo.name,
path: filename,
ref: ctx.payload.pull_request.head.sha
);
let fileContents = util.base64Decode(contents.data.content ?? "");
ctx.octokit.repos.createOrUpdateFileContents(
owner: repo.owner.login,
repo: repo.name,
branch: ctx.payload.pull_request.head.ref,
sha: contents.data.sha,
path: filename,
message: "uppercase {filename}",
content: util.base64Encode(fileContents.uppercase())
);
}
};
class SimpleCredentialsSupplier impl probot.IProbotAppCredentialsSupplier {
pub inflight getId(): str {
return "app id";
}
pub inflight getWebhookSecret(): str {
return "this-is-a-bad-secret";
}
pub inflight getPrivateKey(): str {
return fs.readFile("/path/to/private-key.pem");
}
}
let credentialsSupplier = new SimpleCredentialsSupplier();
let markdown = new probot.ProbotApp(
credentialsSupplier: credentialsSupplier,
onPullRequestOpened: handler,
onPullRequestReopened: handler
);