Skip to content

refactor: extract pushSignedCommits to shared helper, add integration tests - #21584

Merged
pelikhan merged 2 commits into
copilot/implement-feature-planfrom
copilot/sub-pr-21576
Mar 18, 2026
Merged

refactor: extract pushSignedCommits to shared helper, add integration tests#21584
pelikhan merged 2 commits into
copilot/implement-feature-planfrom
copilot/sub-pr-21576

Conversation

CopilotAI commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

pushSignedCommits was duplicated verbatim in both create_pull_request.cjs and push_to_pull_request_branch.cjs. This PR extracts it to a shared helper and adds an integration test suite.

Changes

  • push_signed_commits.cjs (new) — shared helper exporting pushSignedCommits; both callers now require it from here
  • create_pull_request.cjs / push_to_pull_request_branch.cjs — remove the ~92-line inline duplicate each; drop the now-unused path import
  • push_signed_commits.test.cjs (new) — 8 integration tests using a real bare git repo as a local "remote"; GraphQL layer mocked

Integration tests cover:

ScenarioVerified
Single commit via GraphQLmutation query string, input shape, base64 file content
Multiple commitsone call per commit, oldest-first ordering
File deletionsappear in fileChanges.deletions
Empty commitfileChanges has no additions/deletions
No new commitsearly exit, GraphQL never called
GraphQL failurefalls back to git push; remote HEAD confirmed via ls-remote
Multi-line commit bodymessage.body populated
Subject-only messagemessage.body is undefined

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…ests
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
CopilotAI changed the title [WIP] [WIP] Address feedback by moving to helper file and adding integration testrefactor: extract pushSignedCommits to shared helper, add integration testsMar 18, 2026
CopilotAI requested a review from pelikhanMarch 18, 2026 13:22
@github-actions

Copy link
Copy Markdown
Contributor

🟢 Looking good, @Copilot! This is a clean, focused refactor — pulling the ~92-line pushSignedCommits duplicate out of both create_pull_request.cjs and push_to_pull_request_branch.cjs into a proper shared module is exactly the right call, and the 8-scenario integration test suite in push_signed_commits.test.cjs is thorough. The PR description is clear and well-structured.

Everything looks aligned with the project's contribution guidelines and the agentic workflow chain (issue #21572 → PR #21576 → this sub-PR). Ready for maintainer review. 🎉

Generated by Contribution Check ·

@pelikhan
pelikhan marked this pull request as ready for review March 18, 2026 13:37
CopilotAI review requested due to automatic review settings March 18, 2026 13:37
@pelikhan
pelikhan merged commit f1fb6e1 into copilot/implement-feature-planMar 18, 2026
2 checks passed
@pelikhan
pelikhan deleted the copilot/sub-pr-21576 branch March 18, 2026 13:38

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors duplicated signed-commit push logic into a shared helper and adds an integration test suite to validate GraphQL commit replay and git-push fallback behavior.

Changes:

  • Added push_signed_commits.cjs shared helper exporting pushSignedCommits.
  • Updated create_pull_request.cjs and push_to_pull_request_branch.cjs to use the shared helper (and removed now-unused imports).
  • Added push_signed_commits.test.cjs integration tests using a local bare git repo as the remote and a mocked GraphQL layer.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

FileDescription
actions/setup/js/push_to_pull_request_branch.cjsRemoves inline duplicate pushSignedCommits and imports shared helper.
actions/setup/js/create_pull_request.cjsRemoves inline duplicate pushSignedCommits and imports shared helper.
actions/setup/js/push_signed_commits.cjsNew shared implementation of pushSignedCommits.
actions/setup/js/push_signed_commits.test.cjsNew integration tests validating GraphQL payloads and fallback behavior.
Comments suppressed due to low confidence (1)

actions/setup/js/push_signed_commits.cjs:84

  • Same issue for added/modified paths: reading parts[1] from the working tree means replayed commits won’t faithfully represent intermediate states when a file changes across commits. Please source the blob content from the commit being replayed (sha) rather than from the checkout filesystem.
 const content = fs.readFileSync(path.join(cwd, parts[1]));
additions.push({ path: parts[1], contents: content.toString("base64") });

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +79 to +80
const content = fs.readFileSync(path.join(cwd, parts[2]));
additions.push({ path: parts[2], contents: content.toString("base64") });
Comment on lines +76 to +80
} else if (status.startsWith("R") || status.startsWith("C")) {
// Rename or Copy: parts[1] = old path, parts[2] = new path
deletions.push({ path: parts[1] });
const content = fs.readFileSync(path.join(cwd, parts[2]));
additions.push({ path: parts[2], contents: content.toString("base64") });
Comment on lines +106 to +112
} catch (graphqlError) {
core.warning(`pushSignedCommits: GraphQL signed push failed, falling back to git push: ${graphqlError instanceof Error ? graphqlError.message : String(graphqlError)}`);
await exec.exec("git", ["push", "origin", branch], {
cwd,
env: { ...process.env, ...(gitAuthEnv || {}) },
});
}
const headlines = githubClient.graphql.mock.calls.map(c => c[1].input.message.headline);
expect(headlines).toEqual(["Add file-a.txt", "Add file-b.txt"]);
});

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@pelikhan