Skip to content

Commit dc49645

Browse files
fix(codecatalyst): disable New Branch for third-party repo #3258
Problem: When creating a new Dev Env, the option to create a new branch name is shown, but it can't work because CodeCatalyst doesn't support it. Solution: When a third-party repo is selected, disable the New Branch input. Fixes IDE-10216 Signed-off-by: Nikolas Komonen <[email protected]>
1 parent e6658de commit dc49645

File tree

5 files changed

+54
-3
lines changed

5 files changed

+54
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "CodeCatalyst: Disable new branch option when creating new Dev Environment for linked repo"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "CodeCatalyst: `Clone CodeCatalyst Repository` command now only lists non-linked repos"
4+
}

src/codecatalyst/vue/create/backend.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
CodeCatalystProject,
2727
CodeCatalystClient,
2828
DevEnvironment,
29+
isThirdPartyRepo,
2930
} from '../../../shared/clients/codecatalystClient'
3031
import { CancellationError } from '../../../shared/utilities/timeoutUtils'
3132
import { isCloud9 } from '../../../shared/extensionUtilities'
@@ -34,6 +35,7 @@ import { isNonNullable } from '../../../shared/utilities/tsUtils'
3435
import { recordSource } from '../../utils'
3536
import { QuickPickPrompter } from '../../../shared/ui/pickerPrompter'
3637
import { createProjectPrompter } from '../../wizards/selectResource'
38+
import { GetSourceRepositoryCloneUrlsRequest } from 'aws-sdk/clients/codecatalyst'
3739

3840
interface LinkedResponse {
3941
readonly type: 'linked'
@@ -122,6 +124,10 @@ export class CodeCatalystCreateWebview extends VueWebview {
122124
return branches.flatten().promise()
123125
}
124126

127+
public isThirdPartyRepo(codeCatalystRepo: GetSourceRepositoryCloneUrlsRequest): Promise<boolean> {
128+
return isThirdPartyRepo(this.client, codeCatalystRepo)
129+
}
130+
125131
public getAllInstanceDescriptions() {
126132
return getAllInstanceDescriptions()
127133
}

src/codecatalyst/vue/create/source.vue

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@
5151
<!-- New Branch -->
5252
<span class="flex-sizing">
5353
<label class="options-label soft mb-8" style="display: block" for="branch-input"
54-
>Optional - Create a Branch from an Existing Branch</label
54+
>Create Branch - Optional for CodeCatalyst Repos</label
5555
>
5656
<input
5757
id="branch-input"
5858
type="text"
59-
placeholder="branch-name"
59+
:placeholder="newBranchNamePlaceholder"
60+
:disabled="!newBranchNameAllowed"
6061
v-model="model.newBranch"
6162
@input="update"
6263
/>
@@ -116,6 +117,8 @@ export default defineComponent({
116117
branches: {} as Record<string, CodeCatalystBranch[] | undefined>,
117118
loadingProjects: false,
118119
loadingBranches: {} as Record<string, boolean | undefined>,
120+
newBranchNameAllowed: false,
121+
newBranchNamePlaceholder: 'Select branch first...',
119122
}
120123
},
121124
async created() {
@@ -133,6 +136,40 @@ export default defineComponent({
133136
this.useFirstBranch()
134137
}
135138
},
139+
async 'model.selectedBranch'(branch?: CodeCatalystBranch) {
140+
if (this.model.type !== 'linked' || branch === undefined) {
141+
this.newBranchNameAllowed = false
142+
this.newBranchNamePlaceholder = ''
143+
return
144+
}
145+
146+
// Disable user input for new branch name while calculating
147+
this.newBranchNameAllowed = false
148+
this.newBranchNamePlaceholder = 'Loading...'
149+
150+
// Clear the existing new branch value so user does not see it
151+
const previousNewBranch = this.model.newBranch
152+
this.$emit('update:modelValue', { ...this.model, newBranch: undefined })
153+
154+
// Only want to allow users to set a branch name if first party repo
155+
const isThirdPartyRepo = await client.isThirdPartyRepo({
156+
spaceName: branch.org.name,
157+
projectName: branch.project.name,
158+
sourceRepositoryName: branch.repo.name,
159+
})
160+
if (isThirdPartyRepo) {
161+
this.newBranchNamePlaceholder = 'Not Applicable for Linked Repo'
162+
this.newBranchNameAllowed = false
163+
// Clear the new branch in case one was already selected
164+
this.$emit('update:modelValue', { ...this.model, newBranch: undefined })
165+
} else {
166+
// First Party
167+
this.newBranchNamePlaceholder = 'branch-name'
168+
this.newBranchNameAllowed = true
169+
// Since this can have a new branch, set this back to what it previously was
170+
this.$emit('update:modelValue', { ...this.model, newBranch: previousNewBranch })
171+
}
172+
},
136173
},
137174
computed: {
138175
model() {

src/shared/clients/codecatalystClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ export async function excludeThirdPartyRepos(
745745
*
746746
* 1P is CodeCatalyst, 3P is something like Github.
747747
*/
748-
async function isThirdPartyRepo(
748+
export async function isThirdPartyRepo(
749749
client: CodeCatalystClient,
750750
codeCatalystRepo: GetSourceRepositoryCloneUrlsRequest
751751
): Promise<boolean> {

0 commit comments

Comments
 (0)