Skip to content

Commit acaa04e

Browse files
eseligermrnuggetLawnGnome
authored
Add visual step for resolving repositories (#314)
* Add visual step for resolving repositories Also fixes unsupported repositories aborting the workflow. We now simply skip those and let the user know. * Use helper functions to print resolve-repos progress * Add changelog entry * Update CHANGELOG.md Co-authored-by: Adam Harvey <[email protected]> * Print which repositories are being skipped Co-authored-by: Thorsten Ball <[email protected]> Co-authored-by: Adam Harvey <[email protected]>
1 parent 4ea6280 commit acaa04e

File tree

4 files changed

+32
-16
lines changed

4 files changed

+32
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ All notable changes to `src-cli` are documented in this file.
2020

2121
- Repositories without a default branch are skipped when applying/previewing a campaign spec. [#312](https://github.com/sourcegraph/src-cli/pull/312)
2222
- Log files produced when applying/previewing a campaign spec now have the `.log` file extension for easier opening. [#315](https://github.com/sourcegraph/src-cli/pull/315)
23+
- Campaign specs that apply to unsupported repositories will no longer generate an error. Instead, those repositories will be skipped by default and the campaign will be applied to the supported repositories only. [#314](https://github.com/sourcegraph/src-cli/pull/314)
2324

2425
### Fixed
2526

cmd/src/campaigns_common.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,26 @@ func campaignsExecute(ctx context.Context, out *output.Output, svc *campaigns.Se
201201
}
202202
imageProgress.Complete()
203203

204+
pending = campaignsCreatePending(out, "Resolving repositories")
205+
repos, err := svc.ResolveRepositories(ctx, campaignSpec)
206+
if err != nil {
207+
if repoSet, ok := err.(campaigns.UnsupportedRepoSet); ok {
208+
campaignsCompletePending(pending, "Resolved repositories.")
209+
210+
block := out.Block(output.Line(" ", output.StyleWarning, "Some repositories are hosted on unsupported code hosts and will be skipped. Use the -allow-unsupported flag to avoid skipping them."))
211+
for repo := range repoSet {
212+
block.Write(repo.Name)
213+
}
214+
block.Close()
215+
} else {
216+
return "", "", errors.Wrap(err, "resolving repositories")
217+
}
218+
} else {
219+
campaignsCompletePending(pending, "Resolved repositories.")
220+
}
221+
204222
var progress output.Progress
205-
specs, err := svc.ExecuteCampaignSpec(ctx, executor, campaignSpec, func(statuses []*campaigns.TaskStatus) {
223+
specs, err := svc.ExecuteCampaignSpec(ctx, repos, executor, campaignSpec, func(statuses []*campaigns.TaskStatus) {
206224
if progress == nil {
207225
progress = out.Progress([]output.ProgressBar{{
208226
Label: "Executing steps",

internal/campaigns/errors.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77
"github.com/sourcegraph/src-cli/internal/campaigns/graphql"
88
)
99

10-
// unsupportedRepoSet provides a set to manage repositories that are on
10+
// UnsupportedRepoSet provides a set to manage repositories that are on
1111
// unsupported code hosts. This type implements error to allow it to be
1212
// returned directly as an error value if needed.
13-
type unsupportedRepoSet map[*graphql.Repository]struct{}
13+
type UnsupportedRepoSet map[*graphql.Repository]struct{}
1414

15-
func (e unsupportedRepoSet) Error() string {
15+
func (e UnsupportedRepoSet) Error() string {
1616
repos := []string{}
1717
typeSet := map[string]struct{}{}
1818
for repo := range e {
@@ -32,10 +32,10 @@ func (e unsupportedRepoSet) Error() string {
3232
)
3333
}
3434

35-
func (e unsupportedRepoSet) appendRepo(repo *graphql.Repository) {
35+
func (e UnsupportedRepoSet) appendRepo(repo *graphql.Repository) {
3636
e[repo] = struct{}{}
3737
}
3838

39-
func (e unsupportedRepoSet) hasUnsupported() bool {
39+
func (e UnsupportedRepoSet) hasUnsupported() bool {
4040
return len(e) > 0
4141
}

internal/campaigns/service.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,7 @@ func (svc *Service) SetDockerImages(ctx context.Context, spec *CampaignSpec, pro
165165
return nil
166166
}
167167

168-
func (svc *Service) ExecuteCampaignSpec(ctx context.Context, x Executor, spec *CampaignSpec, progress func([]*TaskStatus)) ([]*ChangesetSpec, error) {
169-
repos, err := svc.ResolveRepositories(ctx, spec)
170-
if err != nil {
171-
return nil, errors.Wrap(err, "resolving repositories")
172-
}
173-
168+
func (svc *Service) ExecuteCampaignSpec(ctx context.Context, repos []*graphql.Repository, x Executor, spec *CampaignSpec, progress func([]*TaskStatus)) ([]*ChangesetSpec, error) {
174169
statuses := make([]*TaskStatus, 0, len(repos))
175170
for _, repo := range repos {
176171
ts := x.AddTask(repo, spec.Steps, spec.ChangesetTemplate)
@@ -290,7 +285,7 @@ func (svc *Service) ResolveNamespace(ctx context.Context, namespace string) (str
290285
func (svc *Service) ResolveRepositories(ctx context.Context, spec *CampaignSpec) ([]*graphql.Repository, error) {
291286
final := []*graphql.Repository{}
292287
seen := map[string]struct{}{}
293-
unsupported := unsupportedRepoSet{}
288+
unsupported := UnsupportedRepoSet{}
294289

295290
// TODO: this could be trivially parallelised in the future.
296291
for _, on := range spec.On {
@@ -304,21 +299,23 @@ func (svc *Service) ResolveRepositories(ctx context.Context, spec *CampaignSpec)
304299
if repo.DefaultBranch == nil {
305300
continue
306301
}
302+
seen[repo.ID] = struct{}{}
307303
switch st := strings.ToLower(repo.ExternalRepository.ServiceType); st {
308304
case "github", "gitlab", "bitbucketserver":
309-
310305
default:
311306
unsupported.appendRepo(repo)
307+
if !svc.allowUnsupported {
308+
continue
309+
}
312310
}
313311

314-
seen[repo.ID] = struct{}{}
315312
final = append(final, repo)
316313
}
317314
}
318315
}
319316

320317
if unsupported.hasUnsupported() && !svc.allowUnsupported {
321-
return nil, unsupported
318+
return final, unsupported
322319
}
323320

324321
return final, nil

0 commit comments

Comments
 (0)