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
7 changes: 4 additions & 3 deletions preview/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ inputs:
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
Expand All @@ -48,5 +48,6 @@ runs:
"platform": "${{ inputs.platform }}",
"single-version": "${{ inputs.single-version }}",
}
console.log("Inputs: ", inputs);
const script = require("./preview/scripts/edit-description.js");
await script({inputs, github, context});
23 changes: 19 additions & 4 deletions preview/scripts/edit-description.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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-language"].split(",");
const RTD_PLATFORM = inputs["platform"];
const RTD_SINGLE_VERSION = inputs["single-version"];

github.log.debug(`Language: ${inputs["project-language"]}`);

let RTD_DOMAIN = "";
let RTD_URL = "";

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

let RTD_URLS = [];

if (RTD_SINGLE_VERSION === "true") {
RTD_URL = RTD_PROJECT_DOMAIN;
RTD_URLS.push(RTD_URL);
} else {
RTD_URL = RTD_PROJECT_DOMAIN + `${RTD_PROJECT_LANGUAGE}/${PR_NUMBER}/`;
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}/`;

RTD_URL = RTD_PROJECT_DOMAIN + `${RTD_PROJECT_LANGUAGE}/${PR_NUMBER}/`;
if (RTD_PROJECT_LANGUAGES.length > 1) {
RTD_URL = "\r\n* " + RTD_URL;
}
RTD_URLS.push(RTD_URL);
}
}


const MESSAGE_SEPARATOR_START = `\r\n\r\n<!-- readthedocs-preview ${RTD_PROJECT_SLUG} start -->\r\n`;
const MESSAGE_SEPARATOR_END = `\r\n<!-- readthedocs-preview ${RTD_PROJECT_SLUG} end -->`;
const MESSAGE_TEMPLATE = inputs["message-template"];
Expand All @@ -33,7 +47,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(''));

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