Skip to content

Commit

Permalink
Rename CampaignPlan to PatchSet & ChangesetPlan to Patch (#161)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mrnugget authored Mar 23, 2020
1 parent 1f2d31b commit 20d581c
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 97 deletions.
24 changes: 12 additions & 12 deletions cmd/src/actions_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type actionExecutionCacheKey struct {
}

type actionExecutionCache interface {
get(ctx context.Context, key actionExecutionCacheKey) (result CampaignPlanPatch, ok bool, err error)
set(ctx context.Context, key actionExecutionCacheKey, result CampaignPlanPatch) error
get(ctx context.Context, key actionExecutionCacheKey) (result PatchInput, ok bool, err error)
set(ctx context.Context, key actionExecutionCacheKey, result PatchInput) error
}

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

func (c actionExecutionDiskCache) get(ctx context.Context, key actionExecutionCacheKey) (CampaignPlanPatch, bool, error) {
func (c actionExecutionDiskCache) get(ctx context.Context, key actionExecutionCacheKey) (PatchInput, bool, error) {
path, err := c.cacheFilePath(key)
if err != nil {
return CampaignPlanPatch{}, false, err
return PatchInput{}, false, err
}

data, err := ioutil.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
err = nil // treat as not-found
}
return CampaignPlanPatch{}, false, err
return PatchInput{}, false, err
}

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

return result, true, nil
}

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

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

func (actionExecutionNoOpCache) set(ctx context.Context, key actionExecutionCacheKey, result CampaignPlanPatch) error {
func (actionExecutionNoOpCache) set(ctx context.Context, key actionExecutionCacheKey, result PatchInput) error {
return nil
}
24 changes: 12 additions & 12 deletions cmd/src/actions_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type ActionStep struct {
ImageContentDigest string
}

type CampaignPlanPatch struct {
type PatchInput struct {
Repository string `json:"repository"`
BaseRevision string `json:"baseRevision"`
BaseRef string `json:"baseRef"`
Expand All @@ -64,17 +64,17 @@ Examples:
$ src actions exec -f ~/run-gofmt.json
Execute an action and create a campaign plan from the patches it produced:
Execute an action and create a patch set from the produced patches:
$ src actions exec -f ~/run-gofmt.json -create-plan
$ src actions exec -f ~/run-gofmt.json -create-patchset
Verbosely execute an action and keep the logs available for debugging:
$ src -v actions exec -keep-logs -f ~/run-gofmt.json
Execute an action and pipe the patches it produced to 'src campaign plan create-from-patches':
Execute an action and pipe the patches it produced to 'src campaign patchset create-from-patches':
$ src actions exec -f ~/run-gofmt.json | src campaign plan create-from-patches
$ src actions exec -f ~/run-gofmt.json | src campaign patchset create-from-patches
Read and execute an action definition from standard input:
Expand Down Expand Up @@ -138,8 +138,8 @@ Format of the action JSON files:
keepLogsFlag = flagSet.Bool("keep-logs", false, "Do not remove execution log files when done.")
timeoutFlag = flagSet.Duration("timeout", defaultTimeout, "The maximum duration a single action run can take (excluding the building of Docker images).")

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.")
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.")
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.")
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.")

apiFlags = newAPIFlags(flagSet)
)
Expand Down Expand Up @@ -238,7 +238,7 @@ Format of the action JSON files:
os.Exit(1)
}

if !*createPlanFlag && !*forceCreatePlanFlag {
if !*createPatchSetFlag && !*forceCreatePatchSetFlag {
if err != nil {
logger.ActionFailed(err, patches)
os.Exit(1)
Expand All @@ -256,13 +256,13 @@ Format of the action JSON files:
os.Exit(1)
}

if !*forceCreatePlanFlag {
if !*forceCreatePatchSetFlag {
canInput := isatty.IsTerminal(os.Stdin.Fd()) || isatty.IsCygwinTerminal(os.Stdin.Fd())
if !canInput {
return err
}

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

tmpl, err := parseTemplate("{{friendlyCampaignPlanCreatedMessage .}}")
tmpl, err := parseTemplate("{{friendlyPatchSetCreatedMessage .}}")
if err != nil {
return err
}

return createCampaignPlanFromPatches(apiFlags, patches, tmpl, 100)
return createPatchSetFromPatches(apiFlags, patches, tmpl, 100)
}

// Register the command.
Expand Down
8 changes: 4 additions & 4 deletions cmd/src/actions_exec_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (x *actionExecutor) updateRepoStatus(repo ActionRepo, status ActionRepoStat
if status.FinishedAt.IsZero() {
status.FinishedAt = prev.FinishedAt
}
if status.Patch == (CampaignPlanPatch{}) {
if status.Patch == (PatchInput{}) {
status.Patch = prev.Patch
}
if status.Err == nil {
Expand All @@ -83,12 +83,12 @@ func (x *actionExecutor) updateRepoStatus(repo ActionRepo, status ActionRepoStat
}
}

func (x *actionExecutor) allPatches() []CampaignPlanPatch {
patches := make([]CampaignPlanPatch, 0, len(x.repos))
func (x *actionExecutor) allPatches() []PatchInput {
patches := make([]PatchInput, 0, len(x.repos))
x.reposMu.Lock()
defer x.reposMu.Unlock()
for _, status := range x.repos {
if patch := status.Patch; patch != (CampaignPlanPatch{}) && status.Err == nil {
if patch := status.Patch; patch != (PatchInput{}) && status.Err == nil {
patches = append(patches, status.Patch)
}
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/src/actions_exec_backend_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type ActionRepoStatus struct {
StartedAt time.Time
FinishedAt time.Time

Patch CampaignPlanPatch
Patch PatchInput
Err error
}

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

Expand All @@ -65,7 +65,7 @@ func (x *actionExecutor) do(ctx context.Context, repo ActionRepo) (err error) {
FinishedAt: time.Now(),
}
if len(patch) > 0 {
status.Patch = CampaignPlanPatch{
status.Patch = PatchInput{
Repository: repo.ID,
BaseRevision: repo.Rev,
BaseRef: repo.BaseRef,
Expand Down
4 changes: 2 additions & 2 deletions cmd/src/actions_exec_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (a *actionLogger) Warnf(format string, args ...interface{}) {
}
}

func (a *actionLogger) ActionFailed(err error, patches []CampaignPlanPatch) {
func (a *actionLogger) ActionFailed(err error, patches []PatchInput) {
if !a.verbose {
return
}
Expand All @@ -84,7 +84,7 @@ func (a *actionLogger) ActionFailed(err error, patches []CampaignPlanPatch) {
}
}

func (a *actionLogger) ActionSuccess(patches []CampaignPlanPatch, newLines bool) {
func (a *actionLogger) ActionSuccess(patches []PatchInput, newLines bool) {
if a.verbose {
fmt.Fprintln(os.Stderr)
format := "✔ Action produced %d patches."
Expand Down
2 changes: 1 addition & 1 deletion cmd/src/actions_terminal_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func newTerminalUI(keepLogs bool) func(reposMap map[ActionRepo]ActionRepoStatus)
logFileText = "" // don't show twice
} else {
statusColor = color.GreenString
if status.Patch != (CampaignPlanPatch{}) && status.Patch.Patch != "" {
if status.Patch != (PatchInput{}) && status.Patch.Patch != "" {
fileDiffs, err := diff.ParseMultiFileDiff([]byte(status.Patch.Patch))
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/src/campaigns.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Usage:
The commands are:
create creates campaigns
plans manages campaign plans
patchsets manages patch sets
list lists campaigns
add-changesets adds changesets of a given repository to a campaign
Expand Down
14 changes: 7 additions & 7 deletions cmd/src/campaigns_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ Create a campaign with the given attributes. If -name or -desc are not specified
Examples:
Create a campaign with the given name, branch, description and campaign plan:
Create a campaign with the given name, branch, description and campaign patch set:
$ src campaigns create -name="Format Go code" \
-desc="This campaign runs gofmt over all Go repositories" \
-branch=run-go-fmt \
-plan=Q2FtcGFpZ25QbGFuOjM=
-patchset=Q2FtcGFpZ25QbGFuOjM=
Create a manual campaign with the given name and description and adds two GitHub pull requests to it:
Expand All @@ -47,9 +47,9 @@ Examples:
nameFlag = flagSet.String("name", "", "Name of the campaign.")
descriptionFlag = flagSet.String("desc", "", "Description for the campaign in Markdown.")
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)")
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.")
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.")
draftFlag = flagSet.Bool("draft", false, "Create the campaign as a draft (which won't create pull requests on code hosts)")
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.")
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.")

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

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

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

if needsBranch && *branchFlag == "" {
return &usageError{errors.New("branch cannot be blank for campaigns with a plan")}
return &usageError{errors.New("branch cannot be blank for campaigns with a patch set")}
}
}

Expand Down Expand Up @@ -134,7 +134,7 @@ Examples:
"name": name,
"description": description,
"namespace": namespace,
"plan": nullString(*planIDFlag),
"patchSet": nullString(*patchsetIDFlag),
"draft": *draftFlag,
"branch": *branchFlag,
}
Expand Down
18 changes: 9 additions & 9 deletions cmd/src/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ func parseTemplate(text string) (*template.Template, error) {
"buildVersionHasNewSearchInterface": searchTemplateFuncs["buildVersionHasNewSearchInterface"],
"renderResult": searchTemplateFuncs["renderResult"],

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

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

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

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

return buf.String()
Expand Down
2 changes: 1 addition & 1 deletion cmd/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The commands are:
config manages global, org, and user settings
extsvc manages external services
extensions,ext manages extensions (experimental)
actions runs actions to generate campaign plans (experimental)
actions runs actions to generate patch sets (experimental)
campaigns manages campaigns (experimental)
lsif manages LSIF data
version display and compare the src-cli version against the recommended version for your instance
Expand Down
Loading

0 comments on commit 20d581c

Please sign in to comment.