Skip to content

Commit e85806d

Browse files
committed
Merge branch 'debug-update-mail-to-commit-notes'
2 parents 0d8edbc + bf15787 commit e85806d

File tree

8 files changed

+124
-2
lines changed

8 files changed

+124
-2
lines changed

.vscode/launch.json

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"name": "Launch GitHub Action",
9+
"type": "node",
10+
"request": "launch",
11+
"runtimeArgs": [
12+
"--inspect-brk",
13+
// "--nolazy",
14+
],
15+
"args": [
16+
"${workspaceFolder}/update-mail-to-commit-notes/index.js"
17+
],
18+
"stopOnEntry": false,
19+
"cwd": "${workspaceFolder}",
20+
"runtimeExecutable": null,
21+
"env": {
22+
"NODE_ENV": "development",
23+
"GITGITGADGET_DRY_RUN": "1",
24+
},
25+
"console": "integratedTerminal",
26+
"sourceMaps": true,
27+
"outFiles": [
28+
"${workspaceFolder}/build/**/*.js",
29+
"${workspaceFolder}/dist/**/*.js",
30+
"${workspaceFolder}/lib/**/*.js"
31+
]
32+
},
733
{
834
"name": "Tests",
935
"type": "node",
@@ -18,7 +44,6 @@
1844
],
1945
"stopOnEntry": false,
2046
"cwd": "${workspaceFolder}",
21-
"preLaunchTask": null,
2247
"runtimeExecutable": null,
2348
"env": {
2449
"NODE_ENV": "development"

lib/ci-helper.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ export class CIHelper {
5454
}
5555

5656
public constructor(workDir: string = "git.git", config?: IConfig, skipUpdate?: boolean, gggConfigDir = ".") {
57+
if (process.env.GITGITGADGET_DRY_RUN) {
58+
// Avoid letting VS Code's `GIT_ASKPASS` any push succeed
59+
Object.keys(process.env).forEach((key) => {
60+
if (key.startsWith("GIT_") || key.startsWith("VSCODE_")) {
61+
console.warn(`Deleting environment variable ${key}`);
62+
delete process.env[key];
63+
}
64+
});
65+
process.env.GIT_CONFIG_NOSYSTEM = "1";
66+
process.env.GIT_CONFIG_GLOBAL = "does-not-exist";
67+
68+
// Disable any credential helper
69+
process.env.GIT_CONFIG_PARAMETERS = [process.env.GIT_CONFIG_PARAMETERS, "'credential.helper='"]
70+
.filter((e) => e)
71+
.join(" ");
72+
}
73+
5774
this.config = config !== undefined ? setConfig(config) : getConfig();
5875
this.gggConfigDir = gggConfigDir;
5976
this.workDir = workDir;
@@ -129,6 +146,15 @@ export class CIHelper {
129146
// Ignore, for now
130147
}
131148

149+
if (!this.smtpOptions && process.env.GITGITGADGET_DRY_RUN) {
150+
this.smtpOptions = {
151+
smtpUser: "[email protected]",
152+
smtpHost: "smtp.example.com",
153+
smtpPass: "password",
154+
};
155+
console.log("Using debug SMTP options:", this.smtpOptions);
156+
}
157+
132158
// eslint-disable-next-line security/detect-non-literal-fs-filename
133159
if (!fs.existsSync(this.workDir)) await git(["init", "--bare", "--initial-branch", "unused", this.workDir]);
134160
for (const [key, value] of [
@@ -162,6 +188,23 @@ export class CIHelper {
162188
},
163189
);
164190
console.timeEnd("fetch Git notes");
191+
console.time("forcing `gitgitgadget` notes refs back in time");
192+
await git(["update-ref", "refs/notes/gitgitgadget", "07cbd089352a850817060742d649adb4c4c99445"], {
193+
workDir: this.workDir,
194+
});
195+
console.timeEnd("forcing `gitgitgadget` notes refs back in time");
196+
if (setupOptions?.needsMailToCommitNotes) {
197+
console.time("forcing `commit-to-mail` notes refs back in time");
198+
await git(["update-ref", "refs/notes/commit-to-mail", "de5f0ffd77eabc913e560acb4f3303b6e3df4163"], {
199+
workDir: this.workDir,
200+
});
201+
console.timeEnd("forcing `commit-to-mail` notes refs back in time");
202+
console.time("forcing `mail-to-commit` notes refs back in time");
203+
await git(["update-ref", "refs/notes/mail-to-commit", "92b87ef409b0858d188a371a6af30aa477bc549f"], {
204+
workDir: this.workDir,
205+
});
206+
console.timeEnd("forcing `mail-to-commit` notes refs back in time");
207+
}
165208
this.gggNotesUpdated = true;
166209
if (setupOptions?.needsUpstreamBranches) {
167210
console.time("fetch upstream branches");

lib/git-notes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ type TemporaryNoteIndex = {
2020

2121
export class GitNotes {
2222
public async push(url: string, token: string | undefined = undefined): Promise<void> {
23+
if (process.env.GITGITGADGET_DRY_RUN) {
24+
console.log(`Would push '${this.notesRef}' to ${url}`);
25+
return; // debug mode does not actually do anything
26+
}
2327
const auth = !token
2428
? []
2529
: [

lib/github-glue.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ export class GitHubGlue {
7979
const [, short, completedAt] = match;
8080
const url = `https://github.com/${baseOwner}/${this.repo}/commit/${gitGitCommit}`;
8181

82+
if (process.env.GITGITGADGET_DRY_RUN) {
83+
console.log(`Would annotate ${originalCommit}:\n${gitGitCommit} as ${short} at ${completedAt}\n${url}`);
84+
return -1; // debug mode does not actually do anything
85+
}
8286
await this.ensureAuthenticated(repositoryOwner);
8387
const checks = await this.client.rest.checks.create({
8488
completed_at: completedAt,
@@ -177,6 +181,10 @@ export class GitHubGlue {
177181
* @returns the comment ID and the URL to the comment
178182
*/
179183
public async addPRComment(pullRequest: pullRequestKeyInfo, comment: string): Promise<{ id: number; url: string }> {
184+
if (process.env.GITGITGADGET_DRY_RUN) {
185+
console.log(`Would add comment to ${JSON.stringify(pullRequest)}:\n${comment}`);
186+
return { id: -1, url: "" }; // debug mode does not actually do anything
187+
}
180188
const prKey = getPullRequestKey(pullRequest);
181189

182190
await this.ensureAuthenticated(prKey.owner);
@@ -208,6 +216,10 @@ export class GitHubGlue {
208216
comment: string,
209217
line?: number,
210218
): Promise<{ id: number; url: string }> {
219+
if (process.env.GITGITGADGET_DRY_RUN) {
220+
console.log(`Would add comment to ${JSON.stringify(pullRequest)}, commit ${commit}:\n${comment}`);
221+
return { id: -1, url: "" }; // debug mode does not actually do anything
222+
}
211223
const prKey = getPullRequestKey(pullRequest);
212224

213225
await this.ensureAuthenticated(prKey.owner);
@@ -241,6 +253,10 @@ export class GitHubGlue {
241253
id: number,
242254
comment: string,
243255
): Promise<{ id: number; url: string }> {
256+
if (process.env.GITGITGADGET_DRY_RUN) {
257+
console.log(`Would add reply to ${JSON.stringify(pullRequest)}, id ${id}:\n${comment}`);
258+
return { id: -1, url: "" }; // debug mode does not actually do anything
259+
}
244260
const prKey = getPullRequestKey(pullRequest);
245261

246262
await this.ensureAuthenticated(prKey.owner);
@@ -265,6 +281,10 @@ export class GitHubGlue {
265281
* @returns the PR number
266282
*/
267283
public async updatePR(prKey: pullRequestKey, body?: string, title?: string): Promise<number> {
284+
if (process.env.GITGITGADGET_DRY_RUN) {
285+
console.log(`Would add update ${JSON.stringify(prKey)}:\ntitle: ${title}\nbody: ${body}`);
286+
return prKey.pull_number; // debug mode does not actually do anything
287+
}
268288
await this.ensureAuthenticated(prKey.owner);
269289

270290
const result = await this.client.rest.pulls.update({
@@ -277,6 +297,10 @@ export class GitHubGlue {
277297
}
278298

279299
public async addPRLabels(pullRequest: pullRequestKeyInfo, labels: string[]): Promise<string[]> {
300+
if (process.env.GITGITGADGET_DRY_RUN) {
301+
console.log(`Would add labels to ${JSON.stringify(pullRequest)}:\n${labels.join(", ")}`);
302+
return labels; // debug mode does not actually do anything
303+
}
280304
const prKey = getPullRequestKey(pullRequest);
281305

282306
await this.ensureAuthenticated(prKey.owner);
@@ -290,6 +314,10 @@ export class GitHubGlue {
290314
}
291315

292316
public async closePR(pullRequest: pullRequestKeyInfo, viaMergeCommit: string): Promise<number> {
317+
if (process.env.GITGITGADGET_DRY_RUN) {
318+
console.log(`Would add close ${JSON.stringify(pullRequest)}:\n${viaMergeCommit}`);
319+
return -1; // debug mode does not actually do anything
320+
}
293321
const prKey = getPullRequestKey(pullRequest);
294322

295323
await this.ensureAuthenticated(prKey.owner);
@@ -454,6 +482,16 @@ export class GitHubGlue {
454482
* @param login the GitHub login
455483
*/
456484
public async getGitHubUserInfo(login: string): Promise<IGitHubUser> {
485+
if (process.env.GITGITGADGET_DRY_RUN) {
486+
if (login === "dscho")
487+
return {
488+
489+
login,
490+
name: "Ohai!",
491+
type: "user",
492+
};
493+
throw new Error(`Cannot mock getByUsername: ${login}`);
494+
}
457495
// required to get email
458496
await this.ensureAuthenticated(this.authenticated || this.owner);
459497

lib/patch-series.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ export class PatchSeries {
144144
options.rangeDiff = rangeDiff;
145145
}
146146

147+
if (process.env.GITGITGADGET_DRY_RUN) {
148+
console.log(`Forcing Patch Series to use dry-run mode`);
149+
options = { ...(options || {}), dryRun: true }; // debug mode does not actually do anything
150+
}
151+
147152
return new PatchSeries(notes, options, project, metadata, rangeDiffRanges, patchCount, coverLetter, senderName);
148153
}
149154

lib/send-mail.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ export function parseMBoxMessageIDAndReferences(parsed: IParsedMBox): { messageI
157157
}
158158

159159
export async function sendMail(mail: IParsedMBox, smtpOptions: ISMTPOptions): Promise<string> {
160+
if (process.env.GITGITGADGET_DRY_RUN) {
161+
console.log(`Would send the email:\n${JSON.stringify(mail, null, 2)}`);
162+
return "<Message-ID>"; // debug mode does not actually do anything
163+
}
160164
const transportOpts: SMTPTransport.Options = {
161165
auth: {
162166
pass: smtpOptions.smtpPass,

script/lookup-commit.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ update_gitgit_dir () {
6868
git -C "$GITGIT_DIR" fetch $git_remote refs/notes/commit-to-mail:refs/notes/commit-to-mail ||
6969
die "Could not update refs/notes/commit-to-mail"
7070

71+
git -C "$GITGIT_DIR" update-ref refs/notes/commit-to-mail de5f0ffd77eabc913e560acb4f3303b6e3df4163
72+
git -C "$GITGIT_DIR" update-ref refs/notes/mail-to-commit 92b87ef409b0858d188a371a6af30aa477bc549f
73+
7174
if git -C "$GITGIT_DIR" rev-parse --verify refs/remotes/upstream/seen >/dev/null 2>&1
7275
then
7376
# Let's take 'seen' from the official source at git.git.

script/update-mail-to-commit-notes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ update_gitgit_dir () {
2323
git clone $git_remote "$GITGIT_DIR" ||
2424
die "Could not clone $git_remote to $GITGIT_DIR"
2525

26-
git -C "$GITGIT_DIR" fetch $git_remote \
26+
echo git -C "$GITGIT_DIR" fetch $git_remote \
2727
refs/notes/mail-to-commit:refs/notes/mail-to-commit ||
2828
die "Could not update notes"
2929
}

0 commit comments

Comments
 (0)