Skip to content

Commit

Permalink
add configuration for netlify deploy previews
Browse files Browse the repository at this point in the history
  • Loading branch information
wotnak authored and mstenta committed May 15, 2023
1 parent 6b4d5a6 commit c98d792
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ dist

# TernJS port file
.tern-port

farmOS.org/
8 changes: 8 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[build]
publish = "farmOS.org/public/"
command = "npm run build-preview"

[[headers]]
for = "/*"
[headers.values]
X-Robots-Tag = "noindex"
16 changes: 16 additions & 0 deletions netlifyGetRepoUrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import fetch from 'node-fetch'

const getPullRequestRepoUrl = async () => {
if (process.env.PULL_REQUEST) {
const repoUrl = process.env.REPOSITORY_URL
const repoName = repoUrl.replace("https://github.com/", "")
const branch = process.env.BRANCH
const pullRequest = branch.replace("pull/", "").replace("/head", "")
const response = await fetch(`https://api.github.com/repos/${repoName}/pulls/${pullRequest}`)
const prInfo = await response.json()
console.log(prInfo.head.repo.clone_url)
return
}
console.log(process.env.HEAD)
}
getPullRequestRepoUrl()
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"private": true,
"name": "farmos-community-blog",
"type": "module",
"scripts": {
"build-preview": "rm -rf farmOS.org && git clone --depth=1 https://github.com/farmOS/farmOS.org && cd farmOS.org && npm i && BLOG_REPO=$(node ../netlifyGetRepoUrl.js) BLOG_REPO_BRANCH=$HEAD npm run build"
},
"devDependencies": {
"node-fetch": "^3.3.0"
}
}

0 comments on commit c98d792

Please sign in to comment.