Skip to content

Commit 33a985a

Browse files
authored
Always use api.github.com to determine latest PMD version (#175)
Fixes #173
1 parent 01d65ce commit 33a985a

File tree

7 files changed

+347
-6
lines changed

7 files changed

+347
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ See also [Uploading a SARIF file to GitHub](https://docs.github.com/en/code-secu
7676
7777
|input |required|default|description|
7878
|------------|---|--------|---------------|
79-
|`token` |no |"github.token"|Personal access token (PAT) used to query the latest PMD release and the download URL for PMD.<br>By default the automatic token for GitHub Actions is used.<br>[Learn more about automatic token authentication](https://docs.github.com/en/actions/security-guides/automatic-token-authentication)<br>[Learn more about creating and using encrypted secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets)|
79+
|`token` |no |"github.token"|Personal access token (PAT) used to query the latest PMD release via api.github.com and to determine the modified files of a push/pull request (see option "analyzeModifiedFilesOnly").<br>By default the automatic token for GitHub Actions is used.<br>If this action is used in GHES environment (e.g. the baseUrl is not "api.github.com"), then the token is only used for querying the modified files of a push/pull request. The token won't be used to query the latest PMD release.<br>[Learn more about automatic token authentication](https://docs.github.com/en/actions/security-guides/automatic-token-authentication)<br>[Learn more about creating and using encrypted secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets)|
8080
|`version` |no |"latest"|PMD version to use. Using "latest" automatically downloads the latest version.<br>Available versions: <https://github.com/pmd/pmd/releases><br>Note: Only PMD 6.31.0 and later is supported due to required support for [Sarif report format](https://pmd.github.io/latest/pmd_userdocs_report_formats.html#sarif).|
8181
|`sourcePath`|no |"." |Root directory for sources. Uses by default the current directory|
8282
|`rulesets` |yes| |Comma separated list of ruleset names to use.|

dist/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/licenses.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ The above copyright notice and this permission notice (including the next paragr
206206
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
207207

208208

209+
@octokit/plugin-request-log
210+
MIT
211+
MIT License Copyright (c) 2020 Octokit contributors
212+
213+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
214+
215+
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
216+
217+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
218+
219+
209220
@octokit/plugin-rest-endpoint-methods
210221
MIT
211222
MIT License Copyright (c) 2019 Octokit contributors
@@ -267,6 +278,32 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
267278
THE SOFTWARE.
268279

269280

281+
@octokit/rest
282+
MIT
283+
The MIT License
284+
285+
Copyright (c) 2012 Cloud9 IDE, Inc. (Mike de Boer)
286+
Copyright (c) 2017-2018 Octokit contributors
287+
288+
Permission is hereby granted, free of charge, to any person obtaining a copy
289+
of this software and associated documentation files (the "Software"), to deal
290+
in the Software without restriction, including without limitation the rights
291+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
292+
copies of the Software, and to permit persons to whom the Software is
293+
furnished to do so, subject to the following conditions:
294+
295+
The above copyright notice and this permission notice shall be included in
296+
all copies or substantial portions of the Software.
297+
298+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
299+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
300+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
301+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
302+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
303+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
304+
THE SOFTWARE.
305+
306+
270307
@vercel/ncc
271308
MIT
272309
Copyright 2018 ZEIT, Inc.

lib/util.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
const core = require('@actions/core');
22
const github = require('@actions/github');
3+
const github_defaults = require('@actions/github/lib/utils').defaults;
34
const tc = require('@actions/tool-cache');
45
const exec = require('@actions/exec');
56
const semver = require('semver');
67
const os = require('os');
78
const fs = require('fs').promises;
89
const path = require('path');
10+
const { Octokit } = require('@octokit/rest');
911

1012
// Load at most MAX_PAGE pages when determining modified files.
1113
// This is used both for pull/{pull_number}/files as well as for
@@ -69,7 +71,21 @@ function useNewArgsFormat(pmdVersion) {
6971

7072
async function determinePmdRelease(pmdVersion, token) {
7173
core.debug(`determine release info for ${pmdVersion}`);
72-
const octokit = github.getOctokit(token);
74+
75+
76+
const PUBLIC_GITHUB_API_URL = 'https://api.github.com';
77+
let octokit;
78+
if (github_defaults.baseUrl === PUBLIC_GITHUB_API_URL) {
79+
// only use authenticated token, if on public github and not on a custom GHES instance
80+
octokit = github.getOctokit(token);
81+
core.debug(`Using token to access repos/pmd/pmd/releases/latest on ${github_defaults.baseUrl}`);
82+
} else {
83+
// explicitly overwrite base url to be public github api, as pmd/pmd is only available there
84+
// not using the token, as that would only be valid for GHES
85+
octokit = new Octokit({ baseUrl: PUBLIC_GITHUB_API_URL });
86+
core.debug(`Not using token to access repos/pmd/pmd/releases/latest on ${PUBLIC_GITHUB_API_URL}, as token is for ${github_defaults.baseUrl}`);
87+
}
88+
7389
let release;
7490
if (pmdVersion === 'latest') {
7591
release = await octokit.rest.repos.getLatestRelease({

0 commit comments

Comments
 (0)