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
4 changes: 2 additions & 2 deletions inc/Abilities/GitSyncAbilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private function registerAbilities(): void {
'datamachine/gitsync-submit',
array(
'label' => 'Submit GitSync Binding as Pull Request',
'description' => 'Upload changed local files to the sticky proposal branch (gitsync/<slug>) by default, or to a keyed proposal branch (gitsync/<slug>/<proposal-slug>) when proposal is provided, and open or update a PR against the pinned branch.',
'description' => 'Upload changed local files to the sticky proposal branch (gitsync/<slug>) by default, or to a keyed proposal branch (gitsync/<slug>-<proposal-slug>) when proposal is provided, and open or update a PR against the pinned branch.',
'category' => 'datamachine-code-gitsync',
'input_schema' => array(
'type' => 'object',
Expand All @@ -235,7 +235,7 @@ private function registerAbilities(): void {
'body' => array( 'type' => 'string' ),
'proposal' => array(
'type' => 'string',
'description' => 'Optional proposal key. Omit to reuse gitsync/<slug>; pass a key to use gitsync/<slug>/<proposal-slug>.',
'description' => 'Optional proposal key. Omit to reuse gitsync/<slug>; pass a key to use gitsync/<slug>-<proposal-slug>.',
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion inc/Cli/Commands/GitSyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public function status( array $args, array $assoc_args ): void {
*
* [--proposal=<proposal>]
* : Optional proposal key. Omit to reuse the sticky branch gitsync/<slug>;
* pass a key to use an isolated branch gitsync/<slug>/<proposal-slug>.
* pass a key to use an isolated branch gitsync/<slug>-<proposal-slug>.
*
* [--title=<title>]
* : PR title. Defaults to --message.
Expand Down
4 changes: 2 additions & 2 deletions inc/GitSync/GitSyncProposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct( GitSyncRegistry $registry ) {
* @type string $title PR title. Defaults to $message.
* @type string $body PR body. Defaults to an auto-summary.
* @type string $proposal Optional proposal key. When present,
* submits to gitsync/<slug>/<proposal-slug>.
* submits to gitsync/<slug>-<proposal-slug>.
* }
* @return array<string, mixed>|\WP_Error
*/
Expand Down Expand Up @@ -99,7 +99,7 @@ public function submit( GitSyncBinding $binding, array $args ): array|\WP_Error
}
$feature_branch = self::BRANCH_PREFIX . $binding->slug;
if ( null !== $proposal ) {
$feature_branch .= '/' . $proposal;
$feature_branch .= '-' . $proposal;
}

// Ensure the feature branch exists and points at the current
Expand Down
22 changes: 17 additions & 5 deletions tests/smoke-gitsync.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,9 @@ public static function apiRequest( string $method, string $url, array $body, str
// 9. Submit with a proposal key — isolated branch and PR lookup.
// =========================================================================
echo "\nSubmit (keyed proposal branch)\n";
$GLOBALS['__dmc_http_mock']['GET https://api.github.com/repos/Automattic/a8c-wiki-woocommerce/git/ref/heads/gitsync%2Fwiki%2Fscript-modules'] = array(
// Sticky branch gitsync/wiki already exists from the default submit flow;
// keyed proposals must use a sibling ref so both branches can coexist.
$GLOBALS['__dmc_http_mock']['GET https://api.github.com/repos/Automattic/a8c-wiki-woocommerce/git/ref/heads/gitsync%2Fwiki-script-modules'] = array(
'response' => array( 'code' => 404 ),
'body' => json_encode(array( 'message' => 'Not Found' )),
);
Expand All @@ -474,16 +476,26 @@ public static function apiRequest( string $method, string $url, array $body, str
$keyed = $gs->submit('wiki', array( 'message' => 'script modules update', 'proposal' => 'Script Modules' ));
$assert(! is_wp_error($keyed), 'keyed submit succeeded — ' . ( is_wp_error($keyed) ? $keyed->get_error_message() : '' ));
$assert('script-modules' === ( $keyed['proposal'] ?? null ), 'proposal key normalized to script-modules');
$assert('gitsync/wiki/script-modules' === ( $keyed['branch'] ?? null ), 'keyed feature branch includes proposal slug');
$assert('gitsync/wiki-script-modules' === ( $keyed['branch'] ?? null ), 'keyed feature branch is sibling of sticky branch');
$assert(8 === ( $keyed['pr']['number'] ?? null ), 'keyed proposal opened separate PR');
$keyed_requests = array_slice($GLOBALS['__dmc_http_capture'], $capture_before_keyed);
$keyed_pr_body = null;
$keyed_requests = array_slice($GLOBALS['__dmc_http_capture'], $capture_before_keyed);
$keyed_pr_body = null;
$keyed_ref_body = null;
$saw_nested_keyed_ref = false;
foreach ( $keyed_requests as $request ) {
if ( 'POST' === $request['method'] && str_ends_with($request['url'], '/pulls') ) {
$keyed_pr_body = json_decode((string) $request['body'], true);
}
if ( 'POST' === $request['method'] && str_ends_with($request['url'], '/git/refs') ) {
$keyed_ref_body = json_decode((string) $request['body'], true);
}
if ( str_contains($request['url'], 'gitsync%2Fwiki%2Fscript-modules') ) {
$saw_nested_keyed_ref = true;
}
}
$assert('gitsync/wiki/script-modules' === ( $keyed_pr_body['head'] ?? null ), 'keyed PR uses keyed branch head');
$assert('refs/heads/gitsync/wiki-script-modules' === ( $keyed_ref_body['ref'] ?? null ), 'keyed branch ref coexists with sticky branch namespace');
$assert('gitsync/wiki-script-modules' === ( $keyed_pr_body['head'] ?? null ), 'keyed PR uses keyed branch head');
$assert(false === $saw_nested_keyed_ref, 'keyed submit does not request nested sticky-branch ref');

// =========================================================================
// 10. Submit with nothing changed → nothing_to_submit.
Expand Down
Loading