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

BREAKING CHANGE: Use project API endpoint to get details #43

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions preview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ the description will be edited to include the link to Read the Docs' documentati

These are all the parameters this action supports:
* `project-slug` (**_required_**): Project's slug on Read the Docs. You can find it on your Read the Docs project's details page in the right menu under "Project Slug".
* `project-language` (_optional_): Project's language code on Read the Docs. Example: `en` for English, `es` for Spanish, etc. (default: `en`)
* `message-template` (_optional_): Text message to be injected by the action in the Pull Request description. It supports the following placeholders to be replaced:
* `{docs-pr-index-url}`: URL to the root of the documentation for the Pull Request preview.
* `platform` (_optional_): Read the Docs Community (`community`) or Read the Docs for Business (`business`). (default: `community`)
* `single-version` (_optional_): Set this to `'true'` if your project is single version, so we can link to the correct URL. (default: `'false'`)
8 changes: 0 additions & 8 deletions preview/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ 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-template:
description: "Template message to use for the PR body"
default: |
Expand All @@ -24,10 +20,6 @@ inputs:
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'
required: false

runs:
using: "composite"
Expand Down
25 changes: 19 additions & 6 deletions preview/scripts/edit-description.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
module.exports = async ({inputs, github, context}) => {
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_PLATFORM = inputs["platform"];
const RTD_SINGLE_VERSION = inputs["single-version"];

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

if (RTD_PLATFORM === "community") {
RTD_DOMAIN = "org.readthedocs.build";
RTD_PROJECT_ENDPOINT = `https://readthedocs.org/api/v3/projects/${RTD_PROJECT_SLUG}/`;
} else if (RTD_PLATFORM === "business") {
RTD_DOMAIN = "com.readthedocs.build";
RTD_PROJECT_ENDPOINT = `https://readthedocs.com/api/v3/projects/${RTD_PROJECT_SLUG}/`;
} else {
// Log warning here?
}
const RTD_PROJECT_DOMAIN = `https://${RTD_PROJECT_SLUG}--${PR_NUMBER}.${RTD_DOMAIN}/`;

if (RTD_SINGLE_VERSION === "true") {
// Get project details from the RTD API
const project = await fetch(RTD_PROJECT_ENDPOINT, {}).catch((error) => {
throw new Error(`Failed to fetch project details from Read the Docs API: ${error}`);
}).then((response) => {
if (!response.ok) {
throw new Error(`Failed to fetch project details from Read the Docs API: ${project.statusText}`);
}
return response.json();
});

if (project.versioning_scheme === "single_version_without_translations") {
RTD_URL = RTD_PROJECT_DOMAIN;
} else {
RTD_URL = RTD_PROJECT_DOMAIN + `${RTD_PROJECT_LANGUAGE}/${PR_NUMBER}/`;
} else if (project.versioning_scheme === "multiple_versions_with_translations") {
RTD_URL = RTD_PROJECT_DOMAIN + `${project.language.code}/${PR_NUMBER}/`;
} else if (project.versioning_scheme === "multiple_versions_without_translations") {
RTD_URL = RTD_PROJECT_DOMAIN + `${PR_NUMBER}/`;
}

Comment on lines +31 to 37
Copy link
Member

Choose a reason for hiding this comment

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

You can remove all this block here and use directly urls.documentation that will always point to the correct URL no matter what's the configuration of the project.

Copy link
Author

Choose a reason for hiding this comment

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

That URL doesn't seem to point to the preview, though. Also, #42 (comment) gives me pause to making this change and suggests we should deprecate single-version in favor of versioning-scheme, for example.

const MESSAGE_SEPARATOR_START = `\r\n\r\n<!-- readthedocs-preview ${RTD_PROJECT_SLUG} start -->\r\n`;
Expand Down
Loading