Skip to content

Commit

Permalink
Merge pull request #628 from paambaati/gp/support-forks
Browse files Browse the repository at this point in the history
  • Loading branch information
paambaati committed Oct 21, 2022
2 parents 8788c82 + a0ed69e commit ce39445
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: publish code coverage to code-climate (duh)
if: ${{ github.event_name == 'push' }}
uses: paambaati/codeclimate-action@v3.1.0
uses: paambaati/codeclimate-action@v3.1.1
env:
CC_TEST_REPORTER_ID: 3470adaf12ff7cecdfe5a968ae0e95d098b6ee58c340114e1e90d440ee9e66ab
with:
Expand Down
15 changes: 11 additions & 4 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"branches": [
"main",
"master"
"main"
],
"plugins": [
"@semantic-release/commit-analyzer",
Expand All @@ -11,7 +10,8 @@
"replacements": [
{
"files": [
"README.md"
"README.md",
".github/workflows/ci.yml"
],
"from": "paambaati/codeclimate-action@v.*",
"to": "paambaati/codeclimate-action@v${nextRelease.version}",
Expand All @@ -21,6 +21,12 @@
"hasChanged": true,
"numMatches": 5,
"numReplacements": 5
},
{
"file": ".github/workflows/ci.yml",
"hasChanged": true,
"numMatches": 1,
"numReplacements": 1
}
],
"countMatches": true
Expand All @@ -43,7 +49,8 @@
"package.json",
"package-lock.json",
"CHANGELOG.md",
"README.md"
"README.md",
".github/workflows/ci.yml"
],
"message": "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}"
}
Expand Down
46 changes: 23 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@semantic-release/git": "10.0.1",
"@semantic-release/github": "8.0.6",
"@semantic-release/release-notes-generator": "10.0.3",
"@types/node": "18.11.2",
"@types/node": "18.11.3",
"@types/node-fetch": "2.6.2",
"@types/sinon": "10.0.13",
"@types/tape": "4.13.2",
Expand Down
12 changes: 11 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ const DEFAULT_CODECLIMATE_DEBUG = 'false';
const DEFAULT_COVERAGE_LOCATIONS = '';
const DEFAULT_VERIFY_DOWNLOAD = 'true';

const SUPPORTED_GITHUB_EVENTS = [
// Regular PRs.
'pull_request',
// PRs that were triggered on remote forks.
'pull_request_target',
];

function prepareEnv() {
const env = process.env as { [key: string]: string };

Expand All @@ -35,7 +42,10 @@ function prepareEnv() {
if (env.GIT_BRANCH)
env.GIT_BRANCH = env.GIT_BRANCH.replace(/^refs\/heads\//, ''); // Remove 'refs/heads/' prefix (See https://github.com/paambaati/codeclimate-action/issues/42)

if (process.env.GITHUB_EVENT_NAME === 'pull_request') {
if (
process.env.GITHUB_EVENT_NAME &&
SUPPORTED_GITHUB_EVENTS.includes(process.env.GITHUB_EVENT_NAME)
) {
env.GIT_BRANCH = process.env.GITHUB_HEAD_REF || env.GIT_BRANCH; // Report correct branch for PRs (See https://github.com/paambaati/codeclimate-action/issues/86)
env.GIT_COMMIT_SHA = context.payload.pull_request?.['head']?.['sha']; // Report correct SHA for the head branch (See https://github.com/paambaati/codeclimate-action/issues/140)
}
Expand Down

0 comments on commit ce39445

Please sign in to comment.