Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/initiateNewVote.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:
fi
- name: Generate the vote init commit
run: |
./votes/initiateNewVote/generateNewVote.mjs \
./votes/initiateNewVote/generateVoteInitCommit.mjs \
--remote origin \
--github-repo-name "$GITHUB_REPOSITORY" \
--vote-repository-path . \
Expand Down
6 changes: 3 additions & 3 deletions votes/initiateNewVote/_EDIT_ME.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# 1. Select a subject for the vote. This can be a question addressed to the
# voting members.
subject: REPLACEME
subject: Test test

# 2. You can leave the header instructions as is, or modify them if you see fit.
headerInstructions: |
Expand All @@ -24,8 +24,8 @@ headerInstructions: |
# voters express their preference for each candidates, no matter how many
# there are.
candidates:
- TODO
- TODO
- TODO1
- TODO2

# 4. Pass the following to false if it's important to keep the candidates in the
# order you define above. Presenting candidates in a fixed order tends to
Expand Down
2 changes: 1 addition & 1 deletion votes/initiateNewVote/decryptPrivateKeyAndCloseVote.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url";
import { parseArgs } from "node:util";

import countFromGit from "@node-core/caritat/countBallotsFromGit";
import { findVoteSubPath } from "./getVoteSubpath.mjs";
import { findVoteSubPath } from "./utils/getVoteSubpath.mjs";

const { values: parsedArgs } = parseArgs({
options: {
Expand Down
2 changes: 1 addition & 1 deletion votes/initiateNewVote/generateNewVotePR.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

import { parseArgs } from "node:util";
import { prOptions, createVotePR } from "./_generateNewVotePR.mjs";
import { prOptions, createVotePR } from "./utils/generateNewVotePR.mjs";

const { values: argv } = parseArgs({ options: prOptions });

Expand Down
2 changes: 1 addition & 1 deletion votes/initiateNewVote/getVoteStatus.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { fileURLToPath } from "node:url";

import count from "@node-core/caritat/countParticipationFromGit";
import countFromGit from "@node-core/caritat/countBallotsFromGit";
import { findVoteSubPath } from "./getVoteSubpath.mjs";
import { findVoteSubPath } from "./utils/getVoteSubpath.mjs";

const { allowedVoters, shares } = JSON.parse(argv[2])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { once } from "node:events";
import { spawn } from "node:child_process";
import { exit } from "node:process";
import { Buffer } from "node:buffer";

export const keyServerURL = "hkps://keys.openpgp.org";

export function secretHolderThreshold(argv) {
Expand Down Expand Up @@ -41,46 +36,39 @@ export const prOptions = {
}

export async function createVotePR(argv) {
const cp = spawn(
"gh",
[
"api",
`repos/${argv["github-repo-name"]}/pulls`,
"-F",
"base=main",
"-F",
`head=${argv.branch}`,
"-F",
`title=${argv.subject}`,
"-F",
`body=${argv["pr-intro"] ?? ""},
const response = await fetch(`${process.env.GITHUB_API_URL}/repos/${argv["github-repo-name"]}/pulls`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.GH_TOKEN}`,
'Accept': 'application/vnd.github+json',
'X-GitHub-Api-Version': '2022-11-28',
},
body: JSON.stringify({
base: 'main',
head: argv.branch,
title: argv.subject,
body: `${argv["pr-intro"] ?? ""},

To close the vote, a minimum of ${secretHolderThreshold(argv)} key parts would need to be revealed.

Vote instructions will follow.`,
"--jq",
".html_url",
],
{ stdio: ["inherit", "pipe", "inherit"] }
);
// @ts-ignore toArray does exist!
const out = cp.stdout.toArray();
const [code] = await once(cp, "exit");
if (code !== 0) exit(code);

const prUrl = Buffer.concat(await out)
.toString()
.trim();
}),
});
if (!response.ok) {
throw new Error('Failed to create PR: ' + response.statusText, { cause: response })
}
const { html_url: prURL, url } = await response.json();

{
const cp = spawn(
"gh",
[
"pr",
"edit",
prUrl,
"--body",
`${argv["pr-intro"] ?? ""}
const response = await fetch(url, {
method: 'PATCH',
headers: {
'Authorization': `Bearer ${process.env.GH_TOKEN}`,
'Accept': 'application/vnd.github+json',
'X-GitHub-Api-Version': '2022-11-28',
},
body: JSON.stringify({
body: `${argv["pr-intro"] ?? ""}

Vote instructions:

Expand All @@ -95,12 +83,12 @@ ${argv['secret-holder']?.length ?
run the following command: ${"`"}git node vote ${prUrl} --decrypt-key-part --post-comment${"`"}
` : ''}
`,
],
{ stdio: "inherit" },
);
}),
});

const [code] = await once(cp, "exit");
if (code !== 0) exit(code);
if (!response.ok) {
throw new Error('Failed to edit PR: ' + response.statusText, { cause: response })
}
}

console.log("PR created", prUrl);
Expand Down
Loading