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

fix: un-encode {repo} URL parameter when it's set to github.repository #72

Merged
merged 6 commits into from
Jan 26, 2021
Merged
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
16 changes: 10 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
owner: octokit
repo: request-action
- run: "echo latest release: '${{ steps.get_latest_release.outputs.data }}'"

# Create check run
- name: "Create check run for ${{ github.sha }}"
uses: ./
Expand All @@ -29,9 +30,6 @@ jobs:
route: POST /repos/{owner}/{repo}/check-runs
owner: octokit
repo: request-action
mediaType: | # The | is significant!
previews:
- antiope
name: "Test check run"
head_sha: ${{ github.sha }}
output: | # The | is significant!
Expand All @@ -51,11 +49,17 @@ jobs:
route: PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}
owner: octokit
repo: request-action
mediaType: | # The | is significant!
previews:
- antiope
check_run_id: ${{ fromJson(steps.create_check_run.outputs.data).id }}
conclusion: "success"
status: "completed"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# See https://github.com/octokit/request-action/issues/71
- name: "Un-encode {repo} URL parameter when it's set to github.repository"
uses: ./
with:
route: GET /repos/{repository}
repository: ${{ github.repository }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ jobs:
route: POST /repos/{owner}/{repo}/check-runs
owner: octokit
repo: request-action
mediaType: | # The | is significant!
previews:
- antiope
name: "Test check run"
head_sha: ${{ github.sha }}
output: | # The | is significant!
Expand All @@ -71,9 +68,6 @@ jobs:
route: PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}
owner: octokit
repo: request-action
mediaType: | # The | is significant!
previews:
- antiope
check_run_id: ${{ fromJson(steps.create_check_run.outputs.data).id }}
conclusion: "success"
status: "completed"
Expand Down
24 changes: 18 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,28 @@ async function main() {
core.info(`> ${name}: ${value}`);
}

// workaround for https://github.com/octokit/request-action/issues/71
// un-encode "repo" in /repos/{repo} URL when "repo" parameter is set to ${{ github.repository }}
const { url, body, ...options } = octokit.request.endpoint(
route,
parameters
);
const requestOptions = {
...options,
data: body,
url: url.replace(
/\/repos\/([^/]+)/,
(_, match) => "/repos/" + decodeURIComponent(match)
),
};

core.debug(`route: ${inspect(route)}`);
core.debug(`parameters: ${inspect(parameters)}`);
core.debug(
`parsed request options: ${inspect(
octokit.request.endpoint(route, parameters)
)}`
);
core.debug(`parsed request options: ${inspect(requestOptions)}`);

const time = Date.now();
const { status, headers, data } = await octokit.request(route, parameters);

const { status, headers, data } = await octokit.request(requestOptions);

core.info(`< ${status} ${Date.now() - time}ms`);

Expand Down