Skip to content

Commit da2ce3a

Browse files
feat: add pull request link based on template (#3) (#3)
* feat: add pull request link based on template (#3) * chore: todo comment
1 parent c081933 commit da2ce3a

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

dist/index.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12482,11 +12482,33 @@ const textButton = (text, url) => ({
1248212482
}
1248312483
});
1248412484

12485+
const getDescriptionWidget = (description) => {
12486+
const exists = description.match("\\(\\#(.*)\\)");
12487+
12488+
if (exists !== null) {
12489+
const number = parseInt(exists[1], 10);
12490+
const { owner, repo } = github.context.repo;
12491+
const repoUrl = `https://github.com/${owner}/${repo}`;
12492+
const pullRequestLink = `${repoUrl}/pull/${number}`;
12493+
// TODO: clean up description
12494+
12495+
return {
12496+
content: description,
12497+
button: textButton("OPEN", pullRequestLink)
12498+
};
12499+
}
12500+
12501+
return {
12502+
content: description
12503+
};
12504+
};
12505+
1248512506
const getMessageBody = (name, description, status) => {
1248612507
const { owner, repo } = github.context.repo;
1248712508
const { eventName, sha } = github.context;
1248812509
const { number } = github.context.issue;
1248912510
const repoUrl = `https://github.com/${owner}/${repo}`;
12511+
1249012512
const eventPath =
1249112513
eventName === "pull_request" ? `/pull/${number}` : `/commit/${sha}`;
1249212514
const checksUrl = `${repoUrl}${eventPath}/checks`;
@@ -12517,7 +12539,7 @@ const getMessageBody = (name, description, status) => {
1251712539
{
1251812540
keyValue: {
1251912541
topLabel: "Description",
12520-
content: description
12542+
...getDescriptionWidget(description)
1252112543
}
1252212544
}
1252312545
]

src/services/googleChat.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,33 @@ const textButton = (text, url) => ({
2020
}
2121
});
2222

23+
const getDescriptionWidget = (description) => {
24+
const exists = description.match("\\(\\#(.*)\\)");
25+
26+
if (exists !== null) {
27+
const number = parseInt(exists[1], 10);
28+
const { owner, repo } = github.context.repo;
29+
const repoUrl = `https://github.com/${owner}/${repo}`;
30+
const pullRequestLink = `${repoUrl}/pull/${number}`;
31+
// TODO: clean up description
32+
33+
return {
34+
content: description,
35+
button: textButton("OPEN", pullRequestLink)
36+
};
37+
}
38+
39+
return {
40+
content: description
41+
};
42+
};
43+
2344
const getMessageBody = (name, description, status) => {
2445
const { owner, repo } = github.context.repo;
2546
const { eventName, sha } = github.context;
2647
const { number } = github.context.issue;
2748
const repoUrl = `https://github.com/${owner}/${repo}`;
49+
2850
const eventPath =
2951
eventName === "pull_request" ? `/pull/${number}` : `/commit/${sha}`;
3052
const checksUrl = `${repoUrl}${eventPath}/checks`;
@@ -55,7 +77,7 @@ const getMessageBody = (name, description, status) => {
5577
{
5678
keyValue: {
5779
topLabel: "Description",
58-
content: description
80+
...getDescriptionWidget(description)
5981
}
6082
}
6183
]

0 commit comments

Comments
 (0)