Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AXON-109] Expose toggle switch to push branch to remote (Start work) #137

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
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;
pushBranchToRemote: 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;
pushBranchToRemote: boolean;
}

export interface OpenSettingsAction {
Expand Down
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,
pushBranchToRemote: 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.pushBranchToRemote,
);
}
this.postMessage({
Expand Down
29 changes: 29 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 @@ -181,6 +184,8 @@ const StartWorkPage: React.FunctionComponent = () => {

const handleLocalBranchChange = useCallback(
(event: React.ChangeEvent<{ name?: string | undefined; value: string }>) => {
// spaces are not allowed in branch names
event.target.value = event.target.value.replace(/ /g, '-');
setLocalBranch(event.target.value);
},
[setLocalBranch],
Expand Down Expand Up @@ -246,6 +251,7 @@ const StartWorkPage: React.FunctionComponent = () => {
sourceBranch,
localBranch,
upstream,
pushBranchEnabled,
);
setSubmitState('submit-success');
setSubmitResponse(response);
Expand All @@ -262,6 +268,7 @@ const StartWorkPage: React.FunctionComponent = () => {
sourceBranch,
localBranch,
upstream,
pushBranchEnabled,
]);

const handleOpenSettings = useCallback(() => {
Expand Down Expand Up @@ -702,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 remote
</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,
pushBranchToRemote: 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,
pushBranchToRemote: boolean,
): Promise<StartWorkResponseMessage> => {
return new Promise<StartWorkResponseMessage>((resolve, reject) => {
(async () => {
Expand All @@ -136,6 +138,7 @@ export function useStartWorkController(): [StartWorkState, StartWorkControllerAp
sourceBranch,
targetBranch,
upstream,
pushBranchToRemote,
},
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,
pushBranchToRemote: 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 (pushBranchToRemote) {
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,
pushBranchToRemote: 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.pushBranchToRemote,
);
}

Expand Down Expand Up @@ -138,6 +139,7 @@ export class StartWorkOnBitbucketIssueWebview
destBranch: string,
sourceBranch: Branch,
remote: string,
pushBranchToRemote: 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 (pushBranchToRemote) {
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.pushBranchToRemote,
);
}
const currentUserId = issue.siteDetails.userId;
Expand Down Expand Up @@ -151,6 +151,7 @@ export class StartWorkOnIssueWebview
destBranch: string,
sourceBranch: Branch,
remote: string,
pushBranchToRemote: 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 (pushBranchToRemote) {
await repo.push(remote, destBranch, true);
}
}

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