-
Notifications
You must be signed in to change notification settings - Fork 10
/
action.yaml
62 lines (54 loc) · 2.12 KB
/
action.yaml
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
name: "Read the Docs Pull Request Preview"
author: "@readthedocs"
description: "Update PR description with a link to the rendered version of the documentation on Read the Docs"
branding:
color: gray
icon: robot
inputs:
project-slug:
description: "Project's slug on Read the Docs"
required: true
project-language:
description: "Project's language on Read the Docs"
default: "en"
required: false
message-separator:
description: "Text to separate the original body of the PR from the auto-inserted text"
default: "----------"
required: false
message-template:
description: "Template message to use for the PR body"
default: ":books: Documentation preview :books:: {docs-pr-index-url}"
required: false
runs:
using: "composite"
steps:
- name: "Comment on Pull Request with Read the Docs' preview links"
uses: actions/github-script@v6
with:
script: |
var PR_NUMBER = context.issue.number;
var RTD_PROJECT_SLUG = "${{ inputs.project-slug }}";
var RTD_PROJECT_LANGUAGE = "${{ inputs.project-language }}";
var RTD_URL = `https://${RTD_PROJECT_SLUG}--${PR_NUMBER}.org.readthedocs.build/${RTD_PROJECT_LANGUAGE}/${PR_NUMBER}/`;
var MESSAGE_SEPARATOR = `${{ inputs.message-separator }}`;
var MESSAGE_TEMPLATE = `${{ inputs.message-template }}`;
const { data: pull } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
var body_message = `${MESSAGE_TEMPLATE.replace("{docs-pr-index-url}", RTD_URL)}`;
var body = "";
if (pull.body) {
body = pull.body.split(/\r?\n/);
body = body.slice(0, body.indexOf(MESSAGE_SEPARATOR));
body = body.join("\n").trim()
}
body = body + "\n\n" + MESSAGE_SEPARATOR + "\n\n" + body_message;
github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
body: body,
});