Skip to content

Commit 324e205

Browse files
authored
fix: should work with master or production branches now
2 parents 270b856 + 2a69ae0 commit 324e205

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"files.eol": "\n"
3+
}

dist/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,14 +1838,18 @@ const run = async () => {
18381838
// not the *latest commit* of the PR which is what Netlify uses. Instead,
18391839
// have to use github.context.payload.pull_request.head.sha
18401840
// See: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#pull_request
1841-
const commitSha = github.context.payload.pull_request.head.sha;
1841+
const isPr = 'pull_request' in github.context.payload;
1842+
const commitSha = isPr ? github.context.payload.pull_request.head.sha : github.context.sha;
18421843
const MAX_TIMEOUT = Number(core.getInput('max_timeout')) || 60;
18431844
const siteName = core.getInput('site_name');
18441845
if (!netlifyToken) {
18451846
core.setFailed('Please set NETLIFY_TOKEN env variable to your Netlify Personal Access Token secret');
18461847
}
1848+
18471849
if (!commitSha) {
18481850
core.setFailed('Could not determine GitHub commit');
1851+
} else {
1852+
console.log('Using SHA', commitSha, isPr ? 'from PR' : '');
18491853
}
18501854
if (!siteName) {
18511855
core.setFailed('Required field `site_name` was not provided');
@@ -1867,7 +1871,7 @@ const run = async () => {
18671871
// Most likely, it's the first entry in the response
18681872
// but we correlate it just to be safe
18691873
const commitDeployment = netlifyDeployments.find(
1870-
(d) => d.commit_ref === commitSha && d.context === 'deploy-preview',
1874+
(d) => d.commit_ref === commitSha && d.context === (isPr ? 'deploy-preview' : 'production'),
18711875
);
18721876
if (!commitDeployment) {
18731877
core.setFailed(`Could not find deployment for commit ${commitSha}`);

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,18 @@ const run = async () => {
3232
// not the *latest commit* of the PR which is what Netlify uses. Instead,
3333
// have to use github.context.payload.pull_request.head.sha
3434
// See: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#pull_request
35-
const commitSha = github.context.payload.pull_request.head.sha;
35+
const isPr = 'pull_request' in github.context.payload;
36+
const commitSha = isPr ? github.context.payload.pull_request.head.sha : github.context.sha;
3637
const MAX_TIMEOUT = Number(core.getInput('max_timeout')) || 60;
3738
const siteName = core.getInput('site_name');
3839
if (!netlifyToken) {
3940
core.setFailed('Please set NETLIFY_TOKEN env variable to your Netlify Personal Access Token secret');
4041
}
42+
4143
if (!commitSha) {
4244
core.setFailed('Could not determine GitHub commit');
45+
} else {
46+
console.log('Using SHA', commitSha, isPr ? 'from PR' : '');
4347
}
4448
if (!siteName) {
4549
core.setFailed('Required field `site_name` was not provided');
@@ -61,7 +65,7 @@ const run = async () => {
6165
// Most likely, it's the first entry in the response
6266
// but we correlate it just to be safe
6367
const commitDeployment = netlifyDeployments.find(
64-
(d) => d.commit_ref === commitSha && d.context === 'deploy-preview',
68+
(d) => d.commit_ref === commitSha && d.context === (isPr ? 'deploy-preview' : 'production'),
6569
);
6670
if (!commitDeployment) {
6771
core.setFailed(`Could not find deployment for commit ${commitSha}`);

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,12 @@
4242
},
4343
"husky": {
4444
"hooks": {
45-
"pre-commit": "lint-staged",
45+
"pre-commit": "lint-staged && npm run build && git add dist",
4646
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
4747
}
4848
},
4949
"lint-staged": {
50-
"./*.js": [
51-
"eslint --cache --fix",
52-
"npm run build"
53-
],
50+
"./*.js": "eslint --cache --fix",
5451
"*.md": "prettier --write"
5552
},
5653
"release": {

0 commit comments

Comments
 (0)