-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*: add properties and config file support
- Loading branch information
Showing
4 changed files
with
102 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export default async function getConfig ({ owner, repo, path, github, githubToken, debug = false }) { | ||
if (!github && githubToken) { | ||
const { Octokit } = await import('@octokit/core') | ||
|
||
github = new Octokit({ auth: githubToken }) | ||
} | ||
|
||
try { | ||
const { data } = await github.rest.repos.getContent({ | ||
owner, | ||
repo, | ||
path | ||
}) | ||
const fileContent = Buffer.from(data.content, 'base64').toString('utf8') | ||
if (debug) console.log(fileContent) | ||
return JSON.parse(fileContent) | ||
} catch (err) { | ||
if (debug) console.log(err) | ||
return {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
export default async function getProperties ({ owner, repo, github, githubToken, debug = false, prefix = '' }) { | ||
if (!github && githubToken) { | ||
const { Octokit } = await import('@octokit/core') | ||
|
||
github = new Octokit({ auth: githubToken }) | ||
} | ||
|
||
try { | ||
const properties = await github.request('GET /repos/{owner}/{repo}/properties/values', { | ||
owner, | ||
repo, | ||
headers: { | ||
'X-GitHub-Api-Version': '2022-11-28' | ||
} | ||
}) | ||
if (debug) console.log(properties) | ||
|
||
const output = {} | ||
|
||
// copy properties not starting with prefix to output | ||
properties.data.forEach(c => { | ||
if (!c.property_name.startsWith(prefix)) { | ||
output[c.property_name] = c.value | ||
} | ||
}) | ||
|
||
// copy properties starting with prefix to output | ||
if (prefix) { | ||
properties.data.forEach(c => { | ||
if (c.property_name.startsWith(prefix)) { | ||
const name = c.property_name.substring(prefix.length) | ||
output[name] = c.value | ||
} | ||
}) | ||
} | ||
|
||
return output | ||
} catch (err) { | ||
console.log(err) | ||
return {} | ||
} | ||
} |