Skip to content

Commit 7f6cbd1

Browse files
author
Chris Pine
authored
campaigns: allow user to set git commit author (#297)
* add campaigns git commit author data * updated CHANGELOG
1 parent 91dd7bc commit 7f6cbd1

File tree

6 files changed

+67
-21
lines changed

6 files changed

+67
-21
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ All notable changes to `src-cli` are documented in this file.
1111

1212
## Unreleased changes
1313

14+
- Campaigns specs now include an optional `author` property. (If not included, `src campaigns` generates default values for author name and email.) `src campaigns` now includes the name and email in all changeset specs that it generates.
15+
1416
### Changed
1517

1618
- The default branch for the `src-cli` project has been changed to `main`. [#262](https://github.com/sourcegraph/src-cli/pull/262)

internal/campaigns/campaign_spec.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ type ChangesetTemplate struct {
4343
Published bool `json:"published" yaml:"published"`
4444
}
4545

46+
type GitCommitAuthor struct {
47+
Name string `json:"name" yaml:"name"`
48+
Email string `json:"email" yaml:"email"`
49+
}
50+
4651
type ExpandedGitCommitDescription struct {
47-
Message string `json:"message,omitempty" yaml:"message"`
52+
Message string `json:"message,omitempty" yaml:"message"`
53+
Author *GitCommitAuthor `json:"author,omitempty" yaml:"author"`
4854
}
4955

5056
type ImportChangeset struct {

internal/campaigns/changeset_spec.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type CreatedChangeset struct {
2626
}
2727

2828
type GitCommitDescription struct {
29-
Message string `json:"message"`
30-
Diff string `json:"diff"`
29+
Message string `json:"message"`
30+
Diff string `json:"diff"`
31+
AuthorName string `json:"authorName"`
32+
AuthorEmail string `json:"authorEmail"`
3133
}

internal/campaigns/executor.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,18 @@ func reachedTimeout(cmdCtx context.Context, err error) bool {
255255
}
256256

257257
func createChangesetSpec(task *Task, diff string) *ChangesetSpec {
258+
var authorName string
259+
var authorEmail string
260+
261+
if task.Template.Commit.Author == nil {
262+
// user did not provide author info, so use defaults
263+
authorName = "Sourcegraph"
264+
authorEmail = "[email protected]"
265+
} else {
266+
authorName = task.Template.Commit.Author.Name
267+
authorEmail = task.Template.Commit.Author.Email
268+
}
269+
258270
return &ChangesetSpec{
259271
BaseRepository: task.Repository.ID,
260272
CreatedChangeset: &CreatedChangeset{
@@ -266,8 +278,10 @@ func createChangesetSpec(task *Task, diff string) *ChangesetSpec {
266278
Body: task.Template.Body,
267279
Commits: []GitCommitDescription{
268280
{
269-
Message: task.Template.Commit.Message,
270-
Diff: string(diff),
281+
Message: task.Template.Commit.Message,
282+
AuthorName: authorName,
283+
AuthorEmail: authorEmail,
284+
Diff: string(diff),
271285
},
272286
},
273287
Published: task.Template.Published,

schema/campaign_spec.schema.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,24 @@
131131
"message": {
132132
"type": "string",
133133
"description": "The Git commit message."
134+
},
135+
"author": {
136+
"title": "GitCommitAuthor",
137+
"type": "object",
138+
"description": "The author of the Git commit.",
139+
"additionalProperties": false,
140+
"required": ["name", "email"],
141+
"properties": {
142+
"name": {
143+
"type": "string",
144+
"description": "The Git commit author name."
145+
},
146+
"email": {
147+
"type": "string",
148+
"format": "email",
149+
"description": "The Git commit author email."
150+
}
151+
}
134152
}
135153
}
136154
},

schema/campaign_spec_stringdata.go

Lines changed: 20 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)