mirror of
https://github.com/actions/configure-pages.git
synced 2026-03-30 10:04:52 +00:00
Extract getPagesBaseUrl to separate module
This commit is contained in:
40
src/index.js
40
src/index.js
@@ -1,48 +1,16 @@
|
||||
const core = require('@actions/core')
|
||||
const axios = require('axios')
|
||||
|
||||
const getPagesBaseUrl = require('./get-pages-base-url')
|
||||
|
||||
// All variables we need from the runtime are loaded here
|
||||
const getContext = require('./context')
|
||||
|
||||
async function getPageBaseUrl() {
|
||||
try {
|
||||
const context = getContext()
|
||||
|
||||
const pagesEndpoint = `https://api.github.com/repos/${context.repositoryNwo}/pages`
|
||||
|
||||
core.info("GITHUB_TOKEN : " + context.githubToken)
|
||||
|
||||
core.info(`Get the Base URL to the page with endpoint ${pagesEndpoint}`)
|
||||
const response = await axios.get(
|
||||
pagesEndpoint,
|
||||
{
|
||||
headers: {
|
||||
Accept: 'application/vnd.github.v3+json',
|
||||
Authorization: `Bearer ${context.githubToken}`
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
pageObject = response.data
|
||||
core.info(JSON.stringify(pageObject))
|
||||
|
||||
const siteUrl = new URL(pageObject.html_url)
|
||||
core.setOutput('base_url', siteUrl.href)
|
||||
core.setOutput('origin', siteUrl.origin)
|
||||
core.setOutput('host', siteUrl.host)
|
||||
core.setOutput('base_path', siteUrl.pathname)
|
||||
} catch (e) {
|
||||
console.info('Get on the Page failed', e)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
await getPageBaseUrl()
|
||||
await getPagesBaseUrl(context)
|
||||
} catch (error) {
|
||||
core.setFailed(error)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user