Skip to content

Commit

Permalink
fix gitoid parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Cole Kennedy committed Apr 14, 2023
1 parent 536f9da commit c1e2cca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
11 changes: 0 additions & 11 deletions galadriel.code-workspace

This file was deleted.

36 changes: 22 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//index.js
const core = require("@actions/core");
const exec = require('@actions/exec');
const exec = require("@actions/exec");
const { exit } = require("process");
const process = require("process");
const fs = require("fs");
Expand Down Expand Up @@ -93,18 +93,18 @@ async function run() {

process.env.PATH = `${__dirname}:${process.env.PATH}`;
process.env.PATH = `${process.env.PATH}:/bin:/usr/bin`;

// Change working directory to the root of the repo
process.chdir(process.env.GITHUB_WORKSPACE);

const commandArray = command.match(/(?:[^\s"]+|"[^"]*")+/g);

// Execute the command and capture its output
const runArray = ["witness", ...cmd, "--", ...commandArray],
commandString = runArray.join(" ");

let output = "";
await exec.exec('sh', ['-c', commandString], {
await exec.exec("sh", ["-c", commandString], {
cwd: process.cwd(),
env: process.env,
listeners: {
Expand All @@ -117,14 +117,8 @@ async function run() {
},
});

// Find the Git OID using regex
const match = output.match(/[0-9a-fA-F]{64}/);
if (!match) {
console.error("Failed to extract Git OID from the output");
process.exit(1);
}

const gitOID = match[0];
// Find the Git OID from the output
const gitOID = extractDesiredGitOID(output);
console.log("Extracted Git OID:", gitOID);

// Print the Git OID to the output
Expand Down Expand Up @@ -164,4 +158,18 @@ async function run() {
exit(0);
}

function extractDesiredGitOID(output) {
const lines = output.split("\n");
const desiredLinePrefix = "Stored in archivist as ";

for (const line of lines) {
if (line.startsWith(desiredLinePrefix)) {
const match = line.match(/[0-9a-fA-F]{64}/);
if (match) {
return match[0];
}
}
}
}

run();

0 comments on commit c1e2cca

Please sign in to comment.