Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…loy-configs into fermata-demo
  • Loading branch information
JGreenlee committed Feb 9, 2024
2 parents 7caa6e3 + 06a592e commit 6fe360f
Show file tree
Hide file tree
Showing 48 changed files with 3,590 additions and 18 deletions.
559 changes: 559 additions & 0 deletions .github/ISSUE_TEMPLATE/add-new-config.yml

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions .github/actions/convertIssue/action.yml
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
52 changes: 52 additions & 0 deletions .github/actions/convertIssue/issue-to-json.js
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();
14 changes: 14 additions & 0 deletions .github/actions/convertIssue/package.json
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"
}
}
Loading

0 comments on commit 6fe360f

Please sign in to comment.