Skip to content

Commit

Permalink
fix: un-encode {repo} URL parameter when it's set to `${{ github.repo…
Browse files Browse the repository at this point in the history
…sitory }}` (#72)
  • Loading branch information
gr2m authored Jan 26, 2021
1 parent 2375950 commit 7a09f9e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
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

0 comments on commit 7a09f9e

Please sign in to comment.