-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multiple projects & Read the Docs for Business
Allow repositories to use this action more than once in their repositories. This is useful for monolitic repositories with multiple documentation projects. Others changes included here: - use a separate script instead of hard coding it into YAML - use HTML comment as separator for the injected content - support Read the Docs for Business
- Loading branch information
Showing
2 changed files
with
49 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module.exports = ({inputs, github, context}) => { | ||
var PR_NUMBER = context.issue.number; | ||
var RTD_PROJECT_SLUG = "${{ inputs.project-slug }}"; | ||
var RTD_PROJECT_LANGUAGE = "${{ inputs.project-language }}"; | ||
var RTD_PLATFORM = "${{ inputs.platform }}"; | ||
if (RTD_PLATFORM == "community") { | ||
var RTD_DOMAIN = "org.readthedocs.build"; | ||
} | ||
if (RTD_PLATFORM == "business") { | ||
var RTD_DOMAIN = "com.readthedocs.build"; | ||
} | ||
var RTD_URL = `https://${RTD_PROJECT_SLUG}--${PR_NUMBER}.${RTD_DOMAIN}/${RTD_PROJECT_LANGUAGE}/${PR_NUMBER}/`; | ||
|
||
var MESSAGE_SEPARATOR_START = `<!-- readthedocs-preview ${RTD_PROJECT_SLUG} start -->\n`; | ||
var MESSAGE_SEPARATOR_END = `\n<!-- readthedocs-preview ${RTD_PROJECT_SLUG} end -->`; | ||
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.slice(0, pull.body.indexOf(MESSAGE_SEPARATOR_START)); | ||
body = body + MESSAGE_SEPARATOR_START + body_message + MESSAGE_SEPARATOR_END; | ||
body = body + pull.body.slice(pull.body.indexOf(MESSAGE_SEPARATOR_END) + MESSAGE_SEPARATOR_END.length); | ||
} | ||
|
||
github.rest.pulls.update({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: context.issue.number, | ||
body: body, | ||
}); | ||
} |