Skip to content

Commit 9b93482

Browse files
committed
Expose toggle switch to push branch to origin (Start work)
1 parent 11b2a80 commit 9b93482

File tree

10 files changed

+53
-6
lines changed

10 files changed

+53
-6
lines changed

src/ipc/issueActions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export interface StartWorkAction extends Action {
120120
remoteName: string;
121121
setupJira: boolean;
122122
setupBitbucket: boolean;
123+
pushBranchToOrigin: boolean;
123124
}
124125

125126
export interface OpenStartWorkPageAction extends Action {

src/lib/ipc/fromUI/startWork.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface StartRequestAction {
2727
sourceBranch: Branch;
2828
targetBranch: string;
2929
upstream: string;
30+
pushBranchToOrigin: boolean;
3031
}
3132

3233
export interface OpenSettingsAction {

src/lib/webview/controller/startwork/startWorkActionApi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface StartWorkActionApi {
1717
destinationBranch: string,
1818
sourceBranch: Branch,
1919
remote: string,
20+
pushBranchToOrigin: boolean,
2021
): Promise<void>;
2122
closePage(): void;
2223
getStartWorkConfig(): StartWorkBranchTemplate;

src/lib/webview/controller/startwork/startWorkWebviewController.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export class StartWorkWebviewController implements WebviewController<StartWorkIs
134134
msg.targetBranch,
135135
msg.sourceBranch,
136136
msg.upstream,
137+
msg.pushBranchToOrigin,
137138
);
138139
}
139140
this.postMessage({

src/react/atlascode/startwork/StartWorkPage.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const StartWorkPage: React.FunctionComponent = () => {
9595

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

124+
const togglePushBranchEnabled = useCallback(() => setPushBranchEnabled(!pushBranchEnabled), [pushBranchEnabled]);
125+
123126
const handleTransitionChange = useCallback(
124127
(event: React.ChangeEvent<{ name?: string | undefined; value: any }>) => {
125128
setTransition(event.target.value);
@@ -248,6 +251,7 @@ const StartWorkPage: React.FunctionComponent = () => {
248251
sourceBranch,
249252
localBranch,
250253
upstream,
254+
pushBranchEnabled,
251255
);
252256
setSubmitState('submit-success');
253257
setSubmitResponse(response);
@@ -264,6 +268,7 @@ const StartWorkPage: React.FunctionComponent = () => {
264268
sourceBranch,
265269
localBranch,
266270
upstream,
271+
pushBranchEnabled,
267272
]);
268273

269274
const handleOpenSettings = useCallback(() => {
@@ -704,6 +709,28 @@ const StartWorkPage: React.FunctionComponent = () => {
704709
</Grid>
705710
</Collapse>
706711
</Grid>
712+
<Grid item hidden={submitState === 'submit-success'}>
713+
<Divider />
714+
</Grid>
715+
<Grid item hidden={submitState === 'submit-success'}>
716+
<Grid container spacing={1} direction="row">
717+
<Grid item>
718+
<Switch
719+
color="primary"
720+
size="small"
721+
checked={pushBranchEnabled}
722+
onClick={togglePushBranchEnabled}
723+
/>
724+
</Grid>
725+
<Grid item>
726+
<Typography variant="h4">
727+
<Box fontWeight="fontWeightBold">
728+
Push the new branch to origin
729+
</Box>
730+
</Typography>
731+
</Grid>
732+
</Grid>
733+
</Grid>
707734
<Grid item hidden={submitState === 'submit-success'}>
708735
<Button
709736
variant="contained"

src/react/atlascode/startwork/startWorkController.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface StartWorkControllerApi {
3030
sourceBranch: Branch,
3131
targetBranch: string,
3232
upstream: string,
33+
pushBranchToOrigin: boolean,
3334
) => Promise<{ transistionStatus?: string; branch?: string; upstream?: string }>;
3435
closePage: () => void;
3536
openJiraIssue: () => void;
@@ -122,6 +123,7 @@ export function useStartWorkController(): [StartWorkState, StartWorkControllerAp
122123
sourceBranch: Branch,
123124
targetBranch: string,
124125
upstream: string,
126+
pushBranchToOrigin: boolean,
125127
): Promise<StartWorkResponseMessage> => {
126128
return new Promise<StartWorkResponseMessage>((resolve, reject) => {
127129
(async () => {
@@ -136,6 +138,7 @@ export function useStartWorkController(): [StartWorkState, StartWorkControllerAp
136138
sourceBranch,
137139
targetBranch,
138140
upstream,
141+
pushBranchToOrigin,
139142
},
140143
StartWorkMessageType.StartWorkResponse,
141144
ConnectionTimeout,

src/webview/startwork/vscStartWorkActionApi.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class VSCStartWorkActionApi implements StartWorkActionApi {
5050
destinationBranch: string,
5151
sourceBranch: Branch,
5252
remote: string,
53+
pushBranchToOrigin: boolean,
5354
): Promise<void> {
5455
const scm = Container.bitbucketContext.getRepositoryScm(wsRepo.rootUri)!;
5556

@@ -74,8 +75,10 @@ export class VSCStartWorkActionApi implements StartWorkActionApi {
7475
true,
7576
`${sourceBranch.type === RefType.RemoteHead ? 'remotes/' : ''}${sourceBranch.name}`,
7677
);
77-
await scm.push(remote, destinationBranch, true);
78-
return;
78+
79+
if (pushBranchToOrigin) {
80+
await scm.push(remote, destinationBranch, true);
81+
}
7982
}
8083

8184
getStartWorkConfig(): StartWorkBranchTemplate {

src/webviews/components/issue/StartWorkPage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ export default class StartWorkPage extends WebviewComponent<Emit, Accept, {}, St
261261
transition: this.state.transition,
262262
setupJira: this.state.jiraSetupEnabled,
263263
setupBitbucket: this.isEmptyRepo(this.state.repo) ? false : this.state.bitbucketSetupEnabled,
264+
pushBranchToOrigin: false,
264265
});
265266
};
266267

src/webviews/startWorkOnBitbucketIssueWebview.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export class StartWorkOnBitbucketIssueWebview
105105
e.targetBranchName,
106106
e.sourceBranch,
107107
e.remoteName,
108+
e.pushBranchToOrigin,
108109
);
109110
}
110111

@@ -138,6 +139,7 @@ export class StartWorkOnBitbucketIssueWebview
138139
destBranch: string,
139140
sourceBranch: Branch,
140141
remote: string,
142+
pushBranchToOrigin: boolean,
141143
): Promise<void> {
142144
// checkout if a branch exists already
143145
try {
@@ -160,7 +162,11 @@ export class StartWorkOnBitbucketIssueWebview
160162
true,
161163
`${sourceBranch.type === RefType.RemoteHead ? 'remotes/' : ''}${sourceBranch.name}`,
162164
);
163-
await repo.push(remote, destBranch, true);
165+
166+
if (pushBranchToOrigin) {
167+
await repo.push(remote, destBranch, true);
168+
}
169+
164170
return;
165171
}
166172

src/webviews/startWorkOnIssueWebview.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export class StartWorkOnIssueWebview
6969
});
7070
}
7171
this.updateIssue(data);
72-
return;
7372
}
7473

7574
public async invalidate() {
@@ -113,6 +112,7 @@ export class StartWorkOnIssueWebview
113112
e.targetBranchName,
114113
e.sourceBranch,
115114
e.remoteName,
115+
e.pushBranchToOrigin,
116116
);
117117
}
118118
const currentUserId = issue.siteDetails.userId;
@@ -151,6 +151,7 @@ export class StartWorkOnIssueWebview
151151
destBranch: string,
152152
sourceBranch: Branch,
153153
remote: string,
154+
pushBranchToOrigin: boolean,
154155
): Promise<void> {
155156
// checkout if a branch exists already
156157
try {
@@ -173,8 +174,10 @@ export class StartWorkOnIssueWebview
173174
true,
174175
`${sourceBranch.type === RefType.RemoteHead ? 'remotes/' : ''}${sourceBranch.name}`,
175176
);
176-
await repo.push(remote, destBranch, true);
177-
return;
177+
178+
if (pushBranchToOrigin) {
179+
await repo.push(remote, destBranch, true);
180+
}
178181
}
179182

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

0 commit comments

Comments
 (0)