Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provides multiple language previews #26

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
13 changes: 7 additions & 6 deletions preview/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,41 @@ inputs:
project-slug:
description: "Project's slug on Read the Docs"
required: true
project-language:
project-languages:
Yaminyam marked this conversation as resolved.
Show resolved Hide resolved
description: "Project's language on Read the Docs"
default: "en"
required: false
message-template:
description: "Template message to use for the PR body"
default: |
----
:books: Documentation preview :books:: {docs-pr-index-url}
:books: Documentation preview :books::
{docs-pr-index-url}
Yaminyam marked this conversation as resolved.
Show resolved Hide resolved
required: false
platform:
description: "Read the Docs Community or Read the Docs for Business (community or business)"
default: "community"
required: false
single-version:
description: "Site is a single version project, so link to the top level."
default: 'false'
default: 'false'
required: false

runs:
using: "composite"
steps:
- uses: actions/checkout@v3
with:
repository: "readthedocs/actions"
ref: "v1"
repository: "Yaminyam/actions"
ref: "main"
Comment on lines -37 to +38
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part has been modified for test and must be returned before merging.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #28


- name: "Comment on Pull Request with Read the Docs' preview links"
uses: actions/github-script@v6
with:
script: |
const inputs = {
"project-slug": "${{ inputs.project-slug }}",
"project-language": "${{ inputs.project-language }}",
"project-languages": "${{ inputs.project-languages }}",
"message-template": `${{ inputs.message-template }}`,
"platform": "${{ inputs.platform }}",
"single-version": "${{ inputs.single-version }}",
Expand Down
23 changes: 16 additions & 7 deletions preview/scripts/edit-description.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = async ({inputs, github, context}) => {
const PR_NUMBER = context.issue.number;
const RTD_PROJECT_SLUG = inputs["project-slug"];
const RTD_PROJECT_LANGUAGE = inputs["project-language"];
const RTD_PROJECT_LANGUAGES = inputs["project-languages"].split(",");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of splitting it by ,, this attribute could be a list, right? Like

project-languages:
  - en
  - ja

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

It seems that only string, number, and boolean types are possible as arguments.

const RTD_PLATFORM = inputs["platform"];
const RTD_SINGLE_VERSION = inputs["single-version"];

Expand All @@ -15,12 +15,20 @@ module.exports = async ({inputs, github, context}) => {
} else {
// Log warning here?
}
const RTD_PROJECT_DOMAIN = `https://${RTD_PROJECT_SLUG}--${PR_NUMBER}.${RTD_DOMAIN}/`;

if (RTD_SINGLE_VERSION === "true") {
RTD_URL = RTD_PROJECT_DOMAIN;
} else {
RTD_URL = RTD_PROJECT_DOMAIN + `${RTD_PROJECT_LANGUAGE}/${PR_NUMBER}/`;
let RTD_URLS = [];

for (let i = 0; i < RTD_PROJECT_LANGUAGES.length; i++) {
const RTD_PROJECT_LANGUAGE = RTD_PROJECT_LANGUAGES[i];
const RTD_PROJECT_DOMAIN = `https://${RTD_PROJECT_SLUG}--${PR_NUMBER}.${RTD_DOMAIN}/`;

if (RTD_SINGLE_VERSION === "true") {
RTD_URL = RTD_PROJECT_DOMAIN;
} else {
RTD_URL = RTD_PROJECT_DOMAIN + `${RTD_PROJECT_LANGUAGE}/${PR_NUMBER}/`;
}
Yaminyam marked this conversation as resolved.
Show resolved Hide resolved

RTD_URLS.push(RTD_URL);
}

const MESSAGE_SEPARATOR_START = `\r\n\r\n<!-- readthedocs-preview ${RTD_PROJECT_SLUG} start -->\r\n`;
Expand All @@ -33,7 +41,8 @@ module.exports = async ({inputs, github, context}) => {
pull_number: context.issue.number,
});

const body_message = MESSAGE_TEMPLATE.replace("{docs-pr-index-url}", RTD_URL);

const body_message = MESSAGE_TEMPLATE.replace("{docs-pr-index-url}", RTD_URLS.join("\r\n"));
Yaminyam marked this conversation as resolved.
Show resolved Hide resolved

let body = "";
if (pull.body) {
Expand Down