From 11f2d387dfee3cd441e0934e3a1b6bf439390aa8 Mon Sep 17 00:00:00 2001 From: Rijnard van Tonder Date: Fri, 17 Jan 2020 15:41:55 -0700 Subject: [PATCH] automation: make regex search replace the default campaign (#7844) --- enterprise/internal/a8n/campaign_type.go | 8 ++-- enterprise/internal/a8n/campaign_type_test.go | 4 +- .../regex_search_replace.schema.json | 8 ++-- .../regex_search_replace_stringdata.go | 8 ++-- web/src/e2e/e2e.test.ts | 2 +- .../CampaignPlanSpecificationFields.test.tsx | 2 +- .../form/CampaignPlanSpecificationFields.tsx | 6 ++- ...paignPlanSpecificationFields.test.tsx.snap | 46 +++++++------------ .../campaigns/detail/presentation.ts | 2 +- 9 files changed, 38 insertions(+), 48 deletions(-) diff --git a/enterprise/internal/a8n/campaign_type.go b/enterprise/internal/a8n/campaign_type.go index 02603416dd4..6e5133cbfbd 100644 --- a/enterprise/internal/a8n/campaign_type.go +++ b/enterprise/internal/a8n/campaign_type.go @@ -267,7 +267,7 @@ func (c *comby) generateDiff(ctx context.Context, repo api.RepoName, commit api. type regexSearchReplaceArgs struct { ScopeQuery string `json:"scopeQuery"` - RegexMatch string `json:"regexMatch"` + RegexpMatch string `json:"regexpMatch"` TextReplace string `json:"textReplace"` } @@ -281,16 +281,16 @@ func (c *regexSearchReplace) searchQuery() string { // We add the regexMatch because without it search may only return a // truncated list of file matches. We also add count:10000 to have a // higher chance of finding all matches. - return fmt.Sprintf("%s %s count:10000", c.args.ScopeQuery, c.args.RegexMatch) + return fmt.Sprintf("%s %s count:10000", c.args.ScopeQuery, c.args.RegexpMatch) } func (c *regexSearchReplace) searchQueryForRepo(n api.RepoName) string { - return fmt.Sprintf("repo:%s %s %s count:10000", regexp.QuoteMeta(string(n)), c.args.ScopeQuery, c.args.RegexMatch) + return fmt.Sprintf("repo:%s %s %s count:10000", regexp.QuoteMeta(string(n)), c.args.ScopeQuery, c.args.RegexpMatch) } func (c *regexSearchReplace) generateDiff(ctx context.Context, repo api.RepoName, commit api.CommitID) (string, string, error) { // check that the regex is valid before doing any work. - re, err := regexp.Compile(c.args.RegexMatch) + re, err := regexp.Compile(c.args.RegexpMatch) if err != nil { return "", "", err } diff --git a/enterprise/internal/a8n/campaign_type_test.go b/enterprise/internal/a8n/campaign_type_test.go index 15f6512a4ef..4827e641180 100644 --- a/enterprise/internal/a8n/campaign_type_test.go +++ b/enterprise/internal/a8n/campaign_type_test.go @@ -259,7 +259,7 @@ func TestCampaignType_RegexSearchAndReplace(t *testing.T) { name: "simple search replace", args: regexSearchReplaceArgs{ ScopeQuery: "repo:github", - RegexMatch: "foo", + RegexpMatch: "foo", TextReplace: "bar", }, searchResultsContents: map[string]string{ @@ -278,7 +278,7 @@ func TestCampaignType_RegexSearchAndReplace(t *testing.T) { name: "search replace with match groups", args: regexSearchReplaceArgs{ ScopeQuery: "repo:github", - RegexMatch: "(foo)", + RegexpMatch: "(foo)", TextReplace: "$1${1}bar", }, searchResultsContents: map[string]string{ diff --git a/schema/campaign-types/regex_search_replace.schema.json b/schema/campaign-types/regex_search_replace.schema.json index 2f7335dbb9b..ab74ac08e5b 100644 --- a/schema/campaign-types/regex_search_replace.schema.json +++ b/schema/campaign-types/regex_search_replace.schema.json @@ -1,7 +1,7 @@ { "$id": "regex-search-replace-spec.json#", "$schema": "http://json-schema.org/draft-07/schema#", - "description": "Schema for regex search replace", + "description": "Schema for regexp search replace", "type": "object", "properties": { "scopeQuery": { @@ -9,16 +9,16 @@ "minLength": 1, "description": "Define a scope to narrow down repositories affected by this change. Only GitHub and Bitbucket Server are supported." }, - "regexMatch": { + "regexpMatch": { "type": "string", "minLength": 1, "description": "Match this regular expression. RE2 syntax is supported: https://github.com/google/re2/wiki/Syntax" }, "textReplace": { "type": "string", - "description": "Replace the regexMatch text with this text. You may refer to match groups in regexMatch using $id or ${id} syntax." + "description": "Replace the regexpMatch text with this text. You may refer to match groups in regexpMatch using $id or ${id} syntax." } }, - "required": ["scopeQuery", "regexMatch", "textReplace"], + "required": ["scopeQuery", "regexpMatch", "textReplace"], "additionalProperties": false } diff --git a/schema/campaign-types/regex_search_replace_stringdata.go b/schema/campaign-types/regex_search_replace_stringdata.go index 7c9223eba45..980da56cd33 100644 --- a/schema/campaign-types/regex_search_replace_stringdata.go +++ b/schema/campaign-types/regex_search_replace_stringdata.go @@ -6,7 +6,7 @@ package schema const RegexSearchReplaceCampaignTypeSchemaJSON = `{ "$id": "regex-search-replace-spec.json#", "$schema": "http://json-schema.org/draft-07/schema#", - "description": "Schema for regex search replace", + "description": "Schema for regexp search replace", "type": "object", "properties": { "scopeQuery": { @@ -14,17 +14,17 @@ const RegexSearchReplaceCampaignTypeSchemaJSON = `{ "minLength": 1, "description": "Define a scope to narrow down repositories affected by this change. Only GitHub and Bitbucket Server are supported." }, - "regexMatch": { + "regexpMatch": { "type": "string", "minLength": 1, "description": "Match this regular expression. RE2 syntax is supported: https://github.com/google/re2/wiki/Syntax" }, "textReplace": { "type": "string", - "description": "Replace the regexMatch text with this text. You may refer to match groups in regexMatch using $id or ${id} syntax." + "description": "Replace the regexpMatch text with this text. You may refer to match groups in regexpMatch using $id or ${id} syntax." } }, - "required": ["scopeQuery", "regexMatch", "textReplace"], + "required": ["scopeQuery", "regexpMatch", "textReplace"], "additionalProperties": false } ` diff --git a/web/src/e2e/e2e.test.ts b/web/src/e2e/e2e.test.ts index cd9cba0d09e..29e06ee72f9 100644 --- a/web/src/e2e/e2e.test.ts +++ b/web/src/e2e/e2e.test.ts @@ -1578,7 +1578,7 @@ describe('e2e test suite', () => { test('Create campaign preview for regexp campaign type', async () => { await createCampaignPreview({ specification: JSON.stringify({ - regexMatch: 'this is file ([0-9]+)', + regexpMatch: 'this is file ([0-9]+)', textReplace: 'file $1 this is', scopeQuery: 'repo:github.com/sourcegraph-testing/automation-e2e-test', }), diff --git a/web/src/enterprise/campaigns/detail/form/CampaignPlanSpecificationFields.test.tsx b/web/src/enterprise/campaigns/detail/form/CampaignPlanSpecificationFields.test.tsx index 57a58406a4e..36800930956 100644 --- a/web/src/enterprise/campaigns/detail/form/CampaignPlanSpecificationFields.test.tsx +++ b/web/src/enterprise/campaigns/detail/form/CampaignPlanSpecificationFields.test.tsx @@ -22,7 +22,7 @@ describe('CampaignPlanSpecificationFields', () => { expect(component).toMatchSnapshot() expect(onChange.calledOnce).toBe(true) - expect(onChange.firstCall.args[0].type).toBe('comby') + expect(onChange.firstCall.args[0].type).toBe('regexSearchReplace') expect(onChange.firstCall.args[0].arguments).toMatch(/scopeQuery/) }) diff --git a/web/src/enterprise/campaigns/detail/form/CampaignPlanSpecificationFields.tsx b/web/src/enterprise/campaigns/detail/form/CampaignPlanSpecificationFields.tsx index 524e586ba0f..4c932fa7db2 100644 --- a/web/src/enterprise/campaigns/detail/form/CampaignPlanSpecificationFields.tsx +++ b/web/src/enterprise/campaigns/detail/form/CampaignPlanSpecificationFields.tsx @@ -45,7 +45,7 @@ const defaultInputByType: { [K in CampaignType]: string } = { }`, regexSearchReplace: `{ "scopeQuery": "repo:github.com/foo/bar file:.*", - "regexMatch": "foo", + "regexpMatch": "foo", "textReplace": "bar" }`, } @@ -61,7 +61,9 @@ export const CampaignPlanSpecificationFields: React.FunctionComponent = ( isLightTheme, }) => { const value: CampaignPlanSpecificationFormData = - rawValue !== undefined ? rawValue : { type: 'comby', arguments: defaultInputByType.comby } + rawValue !== undefined + ? rawValue + : { type: 'regexSearchReplace', arguments: defaultInputByType.regexSearchReplace } useEffect(() => { if (rawValue === undefined) { onChange(value) diff --git a/web/src/enterprise/campaigns/detail/form/__snapshots__/CampaignPlanSpecificationFields.test.tsx.snap b/web/src/enterprise/campaigns/detail/form/__snapshots__/CampaignPlanSpecificationFields.test.tsx.snap index 199dde3b46b..710ee930a1d 100644 --- a/web/src/enterprise/campaigns/detail/form/__snapshots__/CampaignPlanSpecificationFields.test.tsx.snap +++ b/web/src/enterprise/campaigns/detail/form/__snapshots__/CampaignPlanSpecificationFields.test.tsx.snap @@ -17,7 +17,7 @@ exports[`CampaignPlanSpecificationFields has initial value and calls onChange 1` className="form-control w-auto d-inline-block e2e-campaign-type" onChange={[Function]} placeholder="Select campaign type" - value="comby" + value="regexSearchReplace" > - - - Learn about comby syntax - -
@@ -145,7 +133,7 @@ exports[`CampaignPlanSpecificationFields manual type editable 1`] = ` @@ -215,7 +203,7 @@ exports[`CampaignPlanSpecificationFields non-manual type editable 1`] = `