Skip to content

Commit

Permalink
Expose toggle switch to push branch to origin (Start work)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomura committed Feb 20, 2025
1 parent 11b2a80 commit 9b93482
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/ipc/issueActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export interface StartWorkAction extends Action {
remoteName: string;
setupJira: boolean;
setupBitbucket: boolean;
pushBranchToOrigin: boolean;
}

export interface OpenStartWorkPageAction extends Action {
Expand Down
1 change: 1 addition & 0 deletions src/lib/ipc/fromUI/startWork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface StartRequestAction {
sourceBranch: Branch;
targetBranch: string;
upstream: string;
pushBranchToOrigin: boolean;
}

export interface OpenSettingsAction {
Expand Down
1 change: 1 addition & 0 deletions src/lib/webview/controller/startwork/startWorkActionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface StartWorkActionApi {
destinationBranch: string,
sourceBranch: Branch,
remote: string,
pushBranchToOrigin: boolean,
): Promise<void>;
closePage(): void;
getStartWorkConfig(): StartWorkBranchTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export class StartWorkWebviewController implements WebviewController<StartWorkIs
msg.targetBranch,
msg.sourceBranch,
msg.upstream,
msg.pushBranchToOrigin,
);
}
this.postMessage({
Expand Down
27 changes: 27 additions & 0 deletions src/react/atlascode/startwork/StartWorkPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const StartWorkPage: React.FunctionComponent = () => {

const [transitionIssueEnabled, setTransitionIssueEnabled] = useState(true);
const [branchSetupEnabled, setbranchSetupEnabled] = useState(true);
const [pushBranchEnabled, setPushBranchEnabled] = useState(false);
const [transition, setTransition] = useState<Transition>(emptyTransition);
const [repository, setRepository] = useState<RepoData>(emptyRepoData);
const [branchType, setBranchType] = useState<BranchType>(emptyPrefix);
Expand All @@ -120,6 +121,8 @@ const StartWorkPage: React.FunctionComponent = () => {
[branchSetupEnabled],
);

const togglePushBranchEnabled = useCallback(() => setPushBranchEnabled(!pushBranchEnabled), [pushBranchEnabled]);

const handleTransitionChange = useCallback(
(event: React.ChangeEvent<{ name?: string | undefined; value: any }>) => {
setTransition(event.target.value);
Expand Down Expand Up @@ -248,6 +251,7 @@ const StartWorkPage: React.FunctionComponent = () => {
sourceBranch,
localBranch,
upstream,
pushBranchEnabled,
);
setSubmitState('submit-success');
setSubmitResponse(response);
Expand All @@ -264,6 +268,7 @@ const StartWorkPage: React.FunctionComponent = () => {
sourceBranch,
localBranch,
upstream,
pushBranchEnabled,
]);

const handleOpenSettings = useCallback(() => {
Expand Down Expand Up @@ -704,6 +709,28 @@ const StartWorkPage: React.FunctionComponent = () => {
</Grid>
</Collapse>
</Grid>
<Grid item hidden={submitState === 'submit-success'}>
<Divider />
</Grid>
<Grid item hidden={submitState === 'submit-success'}>
<Grid container spacing={1} direction="row">
<Grid item>
<Switch
color="primary"
size="small"
checked={pushBranchEnabled}
onClick={togglePushBranchEnabled}
/>
</Grid>
<Grid item>
<Typography variant="h4">
<Box fontWeight="fontWeightBold">
Push the new branch to origin
</Box>
</Typography>
</Grid>
</Grid>
</Grid>
<Grid item hidden={submitState === 'submit-success'}>
<Button
variant="contained"
Expand Down
3 changes: 3 additions & 0 deletions src/react/atlascode/startwork/startWorkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface StartWorkControllerApi {
sourceBranch: Branch,
targetBranch: string,
upstream: string,
pushBranchToOrigin: boolean,
) => Promise<{ transistionStatus?: string; branch?: string; upstream?: string }>;
closePage: () => void;
openJiraIssue: () => void;
Expand Down Expand Up @@ -122,6 +123,7 @@ export function useStartWorkController(): [StartWorkState, StartWorkControllerAp
sourceBranch: Branch,
targetBranch: string,
upstream: string,
pushBranchToOrigin: boolean,
): Promise<StartWorkResponseMessage> => {
return new Promise<StartWorkResponseMessage>((resolve, reject) => {
(async () => {
Expand All @@ -136,6 +138,7 @@ export function useStartWorkController(): [StartWorkState, StartWorkControllerAp
sourceBranch,
targetBranch,
upstream,
pushBranchToOrigin,
},
StartWorkMessageType.StartWorkResponse,
ConnectionTimeout,
Expand Down
7 changes: 5 additions & 2 deletions src/webview/startwork/vscStartWorkActionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class VSCStartWorkActionApi implements StartWorkActionApi {
destinationBranch: string,
sourceBranch: Branch,
remote: string,
pushBranchToOrigin: boolean,
): Promise<void> {
const scm = Container.bitbucketContext.getRepositoryScm(wsRepo.rootUri)!;

Expand All @@ -74,8 +75,10 @@ export class VSCStartWorkActionApi implements StartWorkActionApi {
true,
`${sourceBranch.type === RefType.RemoteHead ? 'remotes/' : ''}${sourceBranch.name}`,
);
await scm.push(remote, destinationBranch, true);
return;

if (pushBranchToOrigin) {
await scm.push(remote, destinationBranch, true);
}
}

getStartWorkConfig(): StartWorkBranchTemplate {
Expand Down
1 change: 1 addition & 0 deletions src/webviews/components/issue/StartWorkPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ export default class StartWorkPage extends WebviewComponent<Emit, Accept, {}, St
transition: this.state.transition,
setupJira: this.state.jiraSetupEnabled,
setupBitbucket: this.isEmptyRepo(this.state.repo) ? false : this.state.bitbucketSetupEnabled,
pushBranchToOrigin: false,
});
};

Expand Down
8 changes: 7 additions & 1 deletion src/webviews/startWorkOnBitbucketIssueWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class StartWorkOnBitbucketIssueWebview
e.targetBranchName,
e.sourceBranch,
e.remoteName,
e.pushBranchToOrigin,
);
}

Expand Down Expand Up @@ -138,6 +139,7 @@ export class StartWorkOnBitbucketIssueWebview
destBranch: string,
sourceBranch: Branch,
remote: string,
pushBranchToOrigin: boolean,
): Promise<void> {
// checkout if a branch exists already
try {
Expand All @@ -160,7 +162,11 @@ export class StartWorkOnBitbucketIssueWebview
true,
`${sourceBranch.type === RefType.RemoteHead ? 'remotes/' : ''}${sourceBranch.name}`,
);
await repo.push(remote, destBranch, true);

if (pushBranchToOrigin) {
await repo.push(remote, destBranch, true);
}

return;
}

Expand Down
9 changes: 6 additions & 3 deletions src/webviews/startWorkOnIssueWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export class StartWorkOnIssueWebview
});
}
this.updateIssue(data);
return;
}

public async invalidate() {
Expand Down Expand Up @@ -113,6 +112,7 @@ export class StartWorkOnIssueWebview
e.targetBranchName,
e.sourceBranch,
e.remoteName,
e.pushBranchToOrigin,
);
}
const currentUserId = issue.siteDetails.userId;
Expand Down Expand Up @@ -151,6 +151,7 @@ export class StartWorkOnIssueWebview
destBranch: string,
sourceBranch: Branch,
remote: string,
pushBranchToOrigin: boolean,
): Promise<void> {
// checkout if a branch exists already
try {
Expand All @@ -173,8 +174,10 @@ export class StartWorkOnIssueWebview
true,
`${sourceBranch.type === RefType.RemoteHead ? 'remotes/' : ''}${sourceBranch.name}`,
);
await repo.push(remote, destBranch, true);
return;

if (pushBranchToOrigin) {
await repo.push(remote, destBranch, true);
}
}

public async updateIssue(issue: MinimalIssue<DetailedSiteInfo>) {
Expand Down

0 comments on commit 9b93482

Please sign in to comment.