forked from e-mission/nrel-openpath-deploy-configs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/e-mission/nrel-openpath-dep…
…loy-configs into fermata-demo
- Loading branch information
Showing
48 changed files
with
3,590 additions
and
18 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,19 @@ | ||
# this action is based on the action by zachleat on github (github-issue-to-json-file) | ||
# https://github.com/zachleat/github-issue-to-json-file/blob/main/action.yml | ||
|
||
name: New Config Issue to JSON | ||
description: Convert GitHub issues for new configs to JSON data files. | ||
runs: | ||
using: node16 | ||
main: issue-to-json.js | ||
|
||
inputs: | ||
folder: | ||
description: The target output directory for the JSON data file. | ||
default: _data/ | ||
issue-template: | ||
description: The YAML file for the GitHub issue form template | ||
required: true | ||
hash-property-name: | ||
description: The object property to use to generate the hash for the file name. | ||
required: true |
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,52 @@ | ||
// adapted from https://github.com/zachleat/github-issue-to-json-file/blob/main/issue-to-json.js | ||
|
||
import { writeFile, mkdir } from "node:fs/promises"; | ||
import path from "node:path"; | ||
|
||
import { getInput, exportVariable, setFailed } from "@actions/core"; | ||
import * as github from "@actions/github"; | ||
|
||
import { parseIssueBody } from "./parse-issue-body.js"; | ||
|
||
function getFileName(abbreviation) { | ||
let filename = abbreviation + '.nrel-op.json'; | ||
return filename; | ||
} | ||
|
||
export async function issueToJson() { | ||
try { | ||
// directory to place the file (should be configs folder) | ||
const outputDir = getInput("folder"); | ||
|
||
if (!github.context.payload.issue) { | ||
setFailed("Cannot find GitHub issue"); | ||
return; | ||
} | ||
|
||
let issueTemplatePath = path.join("./.github/ISSUE_TEMPLATE/", getInput("issue-template")); | ||
|
||
//get the information about of the issue | ||
let { title, number, body, user } = github.context.payload.issue; | ||
|
||
if (!title || !body) { | ||
throw new Error("Unable to parse GitHub issue."); | ||
} | ||
|
||
let configData = await parseIssueBody(issueTemplatePath, body); | ||
|
||
exportVariable("IssueNumber", number); | ||
exportVariable("OpenedBy", user.login); | ||
|
||
// create output dir | ||
await mkdir(outputDir, { recursive: true }); | ||
|
||
let abbrevKey = getInput("hash-property-name"); | ||
abbrevKey = abbrevKey.toLowerCase(); | ||
let fileName = getFileName(configData[ abbrevKey ]); | ||
await writeFile(path.join(outputDir, fileName), JSON.stringify(configData, null, 2)); | ||
} catch (error) { | ||
setFailed(error.message); | ||
} | ||
} | ||
|
||
export default issueToJson(); |
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,14 @@ | ||
{ | ||
"name": "@emission/create-config-from-issue", | ||
"version": "1.0.0", | ||
"description": "Convert issue that follows the new config template to a config json file", | ||
"type": "module", | ||
"main": "issue-to-json.js", | ||
"keywords": [], | ||
"author": "", | ||
"dependencies": { | ||
"@actions/core": "^1.6.0", | ||
"@actions/github": "^5.0.0", | ||
"js-yaml": "^4.1.0" | ||
} | ||
} |
Oops, something went wrong.