mirror of
https://github.com/actions/configure-pages.git
synced 2026-03-30 18:14:51 +00:00
Extract getPagesBaseUrl to separate module
This commit is contained in:
33
src/get-pages-base-url.js
Normal file
33
src/get-pages-base-url.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const core = require('@actions/core')
|
||||
const axios = require('axios')
|
||||
|
||||
async function getPagesBaseUrl({ repositoryNwo, githubToken}) {
|
||||
try {
|
||||
const pagesEndpoint = `https://api.github.com/repos/${repositoryNwo}/pages`
|
||||
|
||||
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 ${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 (error) {
|
||||
core.error('Get on the Page failed', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = getPagesBaseUrl
|
||||
Reference in New Issue
Block a user