Skip to content

Commit 20d581c

Browse files
authored
Rename CampaignPlan to PatchSet & ChangesetPlan to Patch (#161)
And: - "src campaign plan create-from-patches" to "src campaign patchset create-from-patches" - "src action exec -create-plan" to "src action exec -create-patchset" - "src action exec -force-create-plan" to "src action exec -force-create-patchset" Part of sourcegraph/sourcegraph#9106 and required change after https://github.com/sourcegraph/sourcegraph/pull/9196
1 parent 1f2d31b commit 20d581c

12 files changed

+97
-97
lines changed

cmd/src/actions_cache.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ type actionExecutionCacheKey struct {
1818
}
1919

2020
type actionExecutionCache interface {
21-
get(ctx context.Context, key actionExecutionCacheKey) (result CampaignPlanPatch, ok bool, err error)
22-
set(ctx context.Context, key actionExecutionCacheKey, result CampaignPlanPatch) error
21+
get(ctx context.Context, key actionExecutionCacheKey) (result PatchInput, ok bool, err error)
22+
set(ctx context.Context, key actionExecutionCacheKey, result PatchInput) error
2323
}
2424

2525
type actionExecutionDiskCache struct {
@@ -38,33 +38,33 @@ func (c actionExecutionDiskCache) cacheFilePath(key actionExecutionCacheKey) (st
3838
return filepath.Join(c.dir, keyString+".json"), nil
3939
}
4040

41-
func (c actionExecutionDiskCache) get(ctx context.Context, key actionExecutionCacheKey) (CampaignPlanPatch, bool, error) {
41+
func (c actionExecutionDiskCache) get(ctx context.Context, key actionExecutionCacheKey) (PatchInput, bool, error) {
4242
path, err := c.cacheFilePath(key)
4343
if err != nil {
44-
return CampaignPlanPatch{}, false, err
44+
return PatchInput{}, false, err
4545
}
4646

4747
data, err := ioutil.ReadFile(path)
4848
if err != nil {
4949
if os.IsNotExist(err) {
5050
err = nil // treat as not-found
5151
}
52-
return CampaignPlanPatch{}, false, err
52+
return PatchInput{}, false, err
5353
}
5454

55-
var result CampaignPlanPatch
55+
var result PatchInput
5656
if err := json.Unmarshal(data, &result); err != nil {
5757
// Delete the invalid data to avoid causing an error for next time.
5858
if err := os.Remove(path); err != nil {
59-
return CampaignPlanPatch{}, false, errors.Wrap(err, "while deleting cache file with invalid JSON")
59+
return PatchInput{}, false, errors.Wrap(err, "while deleting cache file with invalid JSON")
6060
}
61-
return CampaignPlanPatch{}, false, errors.Wrapf(err, "reading cache file %s", path)
61+
return PatchInput{}, false, errors.Wrapf(err, "reading cache file %s", path)
6262
}
6363

6464
return result, true, nil
6565
}
6666

67-
func (c actionExecutionDiskCache) set(ctx context.Context, key actionExecutionCacheKey, result CampaignPlanPatch) error {
67+
func (c actionExecutionDiskCache) set(ctx context.Context, key actionExecutionCacheKey, result PatchInput) error {
6868
data, err := json.Marshal(result)
6969
if err != nil {
7070
return err
@@ -86,10 +86,10 @@ func (c actionExecutionDiskCache) set(ctx context.Context, key actionExecutionCa
8686
// retrieve cache entries.
8787
type actionExecutionNoOpCache struct{}
8888

89-
func (actionExecutionNoOpCache) get(ctx context.Context, key actionExecutionCacheKey) (result CampaignPlanPatch, ok bool, err error) {
90-
return CampaignPlanPatch{}, false, nil
89+
func (actionExecutionNoOpCache) get(ctx context.Context, key actionExecutionCacheKey) (result PatchInput, ok bool, err error) {
90+
return PatchInput{}, false, nil
9191
}
9292

93-
func (actionExecutionNoOpCache) set(ctx context.Context, key actionExecutionCacheKey, result CampaignPlanPatch) error {
93+
func (actionExecutionNoOpCache) set(ctx context.Context, key actionExecutionCacheKey, result PatchInput) error {
9494
return nil
9595
}

cmd/src/actions_exec.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type ActionStep struct {
3737
ImageContentDigest string
3838
}
3939

40-
type CampaignPlanPatch struct {
40+
type PatchInput struct {
4141
Repository string `json:"repository"`
4242
BaseRevision string `json:"baseRevision"`
4343
BaseRef string `json:"baseRef"`
@@ -64,17 +64,17 @@ Examples:
6464
6565
$ src actions exec -f ~/run-gofmt.json
6666
67-
Execute an action and create a campaign plan from the patches it produced:
67+
Execute an action and create a patch set from the produced patches:
6868
69-
$ src actions exec -f ~/run-gofmt.json -create-plan
69+
$ src actions exec -f ~/run-gofmt.json -create-patchset
7070
7171
Verbosely execute an action and keep the logs available for debugging:
7272
7373
$ src -v actions exec -keep-logs -f ~/run-gofmt.json
7474
75-
Execute an action and pipe the patches it produced to 'src campaign plan create-from-patches':
75+
Execute an action and pipe the patches it produced to 'src campaign patchset create-from-patches':
7676
77-
$ src actions exec -f ~/run-gofmt.json | src campaign plan create-from-patches
77+
$ src actions exec -f ~/run-gofmt.json | src campaign patchset create-from-patches
7878
7979
Read and execute an action definition from standard input:
8080
@@ -138,8 +138,8 @@ Format of the action JSON files:
138138
keepLogsFlag = flagSet.Bool("keep-logs", false, "Do not remove execution log files when done.")
139139
timeoutFlag = flagSet.Duration("timeout", defaultTimeout, "The maximum duration a single action run can take (excluding the building of Docker images).")
140140

141-
createPlanFlag = flagSet.Bool("create-plan", false, "Create a campaign plan from the produced set of patches. When the execution of the action fails in a single repository a prompt will ask to confirm or reject the campaign plan creation.")
142-
forceCreatePlanFlag = flagSet.Bool("force-create-plan", false, "Force creation of campaign plan from the produced set of patches, without asking for confirmation even when the execution of the action failed for a subset of repositories.")
141+
createPatchSetFlag = flagSet.Bool("create-patchset", false, "Create a patch set from the produced set of patches. When the execution of the action fails in a single repository a prompt will ask to confirm or reject the patch set creation.")
142+
forceCreatePatchSetFlag = flagSet.Bool("force-create-patchset", false, "Force creation of patch set from the produced set of patches, without asking for confirmation even when the execution of the action failed for a subset of repositories.")
143143

144144
apiFlags = newAPIFlags(flagSet)
145145
)
@@ -238,7 +238,7 @@ Format of the action JSON files:
238238
os.Exit(1)
239239
}
240240

241-
if !*createPlanFlag && !*forceCreatePlanFlag {
241+
if !*createPatchSetFlag && !*forceCreatePatchSetFlag {
242242
if err != nil {
243243
logger.ActionFailed(err, patches)
244244
os.Exit(1)
@@ -256,13 +256,13 @@ Format of the action JSON files:
256256
os.Exit(1)
257257
}
258258

259-
if !*forceCreatePlanFlag {
259+
if !*forceCreatePatchSetFlag {
260260
canInput := isatty.IsTerminal(os.Stdin.Fd()) || isatty.IsCygwinTerminal(os.Stdin.Fd())
261261
if !canInput {
262262
return err
263263
}
264264

265-
c, _ := askForConfirmation(fmt.Sprintf("Create a campaign plan for the produced patches anyway?"))
265+
c, _ := askForConfirmation(fmt.Sprintf("Create a patch set for the produced patches anyway?"))
266266
if !c {
267267
return err
268268
}
@@ -271,12 +271,12 @@ Format of the action JSON files:
271271
logger.ActionSuccess(patches, false)
272272
}
273273

274-
tmpl, err := parseTemplate("{{friendlyCampaignPlanCreatedMessage .}}")
274+
tmpl, err := parseTemplate("{{friendlyPatchSetCreatedMessage .}}")
275275
if err != nil {
276276
return err
277277
}
278278

279-
return createCampaignPlanFromPatches(apiFlags, patches, tmpl, 100)
279+
return createPatchSetFromPatches(apiFlags, patches, tmpl, 100)
280280
}
281281

282282
// Register the command.

cmd/src/actions_exec_backend.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (x *actionExecutor) updateRepoStatus(repo ActionRepo, status ActionRepoStat
6969
if status.FinishedAt.IsZero() {
7070
status.FinishedAt = prev.FinishedAt
7171
}
72-
if status.Patch == (CampaignPlanPatch{}) {
72+
if status.Patch == (PatchInput{}) {
7373
status.Patch = prev.Patch
7474
}
7575
if status.Err == nil {
@@ -83,12 +83,12 @@ func (x *actionExecutor) updateRepoStatus(repo ActionRepo, status ActionRepoStat
8383
}
8484
}
8585

86-
func (x *actionExecutor) allPatches() []CampaignPlanPatch {
87-
patches := make([]CampaignPlanPatch, 0, len(x.repos))
86+
func (x *actionExecutor) allPatches() []PatchInput {
87+
patches := make([]PatchInput, 0, len(x.repos))
8888
x.reposMu.Lock()
8989
defer x.reposMu.Unlock()
9090
for _, status := range x.repos {
91-
if patch := status.Patch; patch != (CampaignPlanPatch{}) && status.Err == nil {
91+
if patch := status.Patch; patch != (PatchInput{}) && status.Err == nil {
9292
patches = append(patches, status.Patch)
9393
}
9494
}

cmd/src/actions_exec_backend_runner.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type ActionRepoStatus struct {
2929
StartedAt time.Time
3030
FinishedAt time.Time
3131

32-
Patch CampaignPlanPatch
32+
Patch PatchInput
3333
Err error
3434
}
3535

@@ -41,7 +41,7 @@ func (x *actionExecutor) do(ctx context.Context, repo ActionRepo) (err error) {
4141
} else if ok {
4242
status := ActionRepoStatus{Cached: true, Patch: result}
4343
x.updateRepoStatus(repo, status)
44-
x.logger.RepoCacheHit(repo, status.Patch != CampaignPlanPatch{})
44+
x.logger.RepoCacheHit(repo, status.Patch != PatchInput{})
4545
return nil
4646
}
4747

@@ -65,7 +65,7 @@ func (x *actionExecutor) do(ctx context.Context, repo ActionRepo) (err error) {
6565
FinishedAt: time.Now(),
6666
}
6767
if len(patch) > 0 {
68-
status.Patch = CampaignPlanPatch{
68+
status.Patch = PatchInput{
6969
Repository: repo.ID,
7070
BaseRevision: repo.Rev,
7171
BaseRef: repo.BaseRef,

cmd/src/actions_exec_logger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (a *actionLogger) Warnf(format string, args ...interface{}) {
6262
}
6363
}
6464

65-
func (a *actionLogger) ActionFailed(err error, patches []CampaignPlanPatch) {
65+
func (a *actionLogger) ActionFailed(err error, patches []PatchInput) {
6666
if !a.verbose {
6767
return
6868
}
@@ -84,7 +84,7 @@ func (a *actionLogger) ActionFailed(err error, patches []CampaignPlanPatch) {
8484
}
8585
}
8686

87-
func (a *actionLogger) ActionSuccess(patches []CampaignPlanPatch, newLines bool) {
87+
func (a *actionLogger) ActionSuccess(patches []PatchInput, newLines bool) {
8888
if a.verbose {
8989
fmt.Fprintln(os.Stderr)
9090
format := "✔ Action produced %d patches."

cmd/src/actions_terminal_ui.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func newTerminalUI(keepLogs bool) func(reposMap map[ActionRepo]ActionRepoStatus)
7777
logFileText = "" // don't show twice
7878
} else {
7979
statusColor = color.GreenString
80-
if status.Patch != (CampaignPlanPatch{}) && status.Patch.Patch != "" {
80+
if status.Patch != (PatchInput{}) && status.Patch.Patch != "" {
8181
fileDiffs, err := diff.ParseMultiFileDiff([]byte(status.Patch.Patch))
8282
if err != nil {
8383
panic(err)

cmd/src/campaigns.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Usage:
1919
The commands are:
2020
2121
create creates campaigns
22-
plans manages campaign plans
22+
patchsets manages patch sets
2323
list lists campaigns
2424
add-changesets adds changesets of a given repository to a campaign
2525

cmd/src/campaigns_create.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ Create a campaign with the given attributes. If -name or -desc are not specified
2121
2222
Examples:
2323
24-
Create a campaign with the given name, branch, description and campaign plan:
24+
Create a campaign with the given name, branch, description and campaign patch set:
2525
2626
$ src campaigns create -name="Format Go code" \
2727
-desc="This campaign runs gofmt over all Go repositories" \
2828
-branch=run-go-fmt \
29-
-plan=Q2FtcGFpZ25QbGFuOjM=
29+
-patchset=Q2FtcGFpZ25QbGFuOjM=
3030
3131
Create a manual campaign with the given name and description and adds two GitHub pull requests to it:
3232
@@ -47,9 +47,9 @@ Examples:
4747
nameFlag = flagSet.String("name", "", "Name of the campaign.")
4848
descriptionFlag = flagSet.String("desc", "", "Description for the campaign in Markdown.")
4949
namespaceFlag = flagSet.String("namespace", "", "ID of the namespace under which to create the campaign. The namespace can be the GraphQL ID of a Sourcegraph user or organisation. If not specified, the ID of the authenticated user is queried and used. (Required)")
50-
planIDFlag = flagSet.String("plan", "", "ID of campaign plan the campaign should turn into changesets. If no plan is specified, a campaign is created to which changesets can be added manually.")
50+
patchsetIDFlag = flagSet.String("patchset", "", "ID of patch set the campaign should turn into changesets. If no patch set is specified, a campaign is created to which changesets can be added manually.")
5151
draftFlag = flagSet.Bool("draft", false, "Create the campaign as a draft (which won't create pull requests on code hosts)")
52-
branchFlag = flagSet.String("branch", "", "Name of the branch that will be created in each repository on the code host. Required for Sourcegraph >= 3.13 when 'plan' is specified.")
52+
branchFlag = flagSet.String("branch", "", "Name of the branch that will be created in each repository on the code host. Required for Sourcegraph >= 3.13 when 'patchset' is specified.")
5353

5454
changesetsFlag = flagSet.Int("changesets", 1000, "Returns the first n changesets per campaign.")
5555

@@ -86,7 +86,7 @@ Examples:
8686
return &usageError{errors.New("campaign description cannot be blank")}
8787
}
8888

89-
if *planIDFlag != "" {
89+
if *patchsetIDFlag != "" {
9090
// We only need to check for -branch if the Sourcegraph version is >= 3.13
9191
version, err := getSourcegraphVersion()
9292
if err != nil {
@@ -98,7 +98,7 @@ Examples:
9898
}
9999

100100
if needsBranch && *branchFlag == "" {
101-
return &usageError{errors.New("branch cannot be blank for campaigns with a plan")}
101+
return &usageError{errors.New("branch cannot be blank for campaigns with a patch set")}
102102
}
103103
}
104104

@@ -134,7 +134,7 @@ Examples:
134134
"name": name,
135135
"description": description,
136136
"namespace": namespace,
137-
"plan": nullString(*planIDFlag),
137+
"patchSet": nullString(*patchsetIDFlag),
138138
"draft": *draftFlag,
139139
"branch": *branchFlag,
140140
}

cmd/src/format.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ func parseTemplate(text string) (*template.Template, error) {
9494
"buildVersionHasNewSearchInterface": searchTemplateFuncs["buildVersionHasNewSearchInterface"],
9595
"renderResult": searchTemplateFuncs["renderResult"],
9696

97-
// `src campaign plans create-from-patches`
98-
"friendlyCampaignPlanCreatedMessage": func(campaignPlan CampaignPlan) string {
97+
// `src campaign patchset create-from-patches`
98+
"friendlyPatchSetCreatedMessage": func(patchSet PatchSet) string {
9999
var buf bytes.Buffer
100100
fmt.Fprintln(&buf)
101-
fmt.Fprintln(&buf, color.HiGreenString("✔ Campaign plan saved."), "\n\nPreview and create this campaign on Sourcegraph using one of the following options:")
101+
fmt.Fprintln(&buf, color.HiGreenString("✔ Patch set saved."), "\n\nPreview and create a campaign on Sourcegraph using one of the following options:")
102102
fmt.Fprintln(&buf)
103-
fmt.Fprintln(&buf, " ", color.HiCyanString("▶ Web:"), campaignPlan.PreviewURL, color.HiBlackString("or"))
104-
cliCommand := fmt.Sprintf("src campaigns create -plan=%s -branch=DESIRED-BRANCH-NAME", campaignPlan.ID)
103+
fmt.Fprintln(&buf, " ", color.HiCyanString("▶ Web:"), patchSet.PreviewURL, color.HiBlackString("or"))
104+
cliCommand := fmt.Sprintf("src campaigns create -patchset=%s -branch=DESIRED-BRANCH-NAME", patchSet.ID)
105105
fmt.Fprintln(&buf, " ", color.HiCyanString("▶ CLI:"), cliCommand)
106106

107107
// Hacky to do this in a formatting helper, but better than
@@ -112,14 +112,14 @@ func parseTemplate(text string) (*template.Template, error) {
112112
return buf.String()
113113
}
114114

115-
supportsUpdatingPlan, err := sourcegraphVersionCheck(version, ">= 3.13-0", "2020-02-14")
115+
supportsUpdatingPatchSet, err := sourcegraphVersionCheck(version, ">= 3.13-0", "2020-02-14")
116116
if err != nil {
117117
return buf.String()
118118
}
119119

120-
if supportsUpdatingPlan {
121-
fmt.Fprintln(&buf, "\nTo update an existing campaign using this campaign plan:")
122-
fmt.Fprintln(&buf, "\n ", color.HiCyanString("▶ Web:"), strings.Replace(campaignPlan.PreviewURL, "/new", "/update", 1))
120+
if supportsUpdatingPatchSet {
121+
fmt.Fprintln(&buf, "\nTo update an existing campaign using this patch set:")
122+
fmt.Fprintln(&buf, "\n ", color.HiCyanString("▶ Web:"), strings.Replace(patchSet.PreviewURL, "/new", "/update", 1))
123123
}
124124

125125
return buf.String()

cmd/src/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The commands are:
3434
config manages global, org, and user settings
3535
extsvc manages external services
3636
extensions,ext manages extensions (experimental)
37-
actions runs actions to generate campaign plans (experimental)
37+
actions runs actions to generate patch sets (experimental)
3838
campaigns manages campaigns (experimental)
3939
lsif manages LSIF data
4040
version display and compare the src-cli version against the recommended version for your instance

0 commit comments

Comments
 (0)