Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ All notable changes to `src-cli` are documented in this file.

## Unreleased changes

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

### Changed

- The default branch for the `src-cli` project has been changed to `main`. [#262](https://github.com/sourcegraph/src-cli/pull/262)
Expand Down
8 changes: 7 additions & 1 deletion internal/campaigns/campaign_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ type ChangesetTemplate struct {
Published bool `json:"published" yaml:"published"`
}

type GitCommitAuthor struct {
Name string `json:"name" yaml:"name"`
Email string `json:"email" yaml:"email"`
}

type ExpandedGitCommitDescription struct {
Message string `json:"message,omitempty" yaml:"message"`
Message string `json:"message,omitempty" yaml:"message"`
Author *GitCommitAuthor `json:"author,omitempty" yaml:"author"`
}

type ImportChangeset struct {
Expand Down
6 changes: 4 additions & 2 deletions internal/campaigns/changeset_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type CreatedChangeset struct {
}

type GitCommitDescription struct {
Message string `json:"message"`
Diff string `json:"diff"`
Message string `json:"message"`
Diff string `json:"diff"`
AuthorName string `json:"authorName"`
AuthorEmail string `json:"authorEmail"`
}
18 changes: 16 additions & 2 deletions internal/campaigns/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@ func reachedTimeout(cmdCtx context.Context, err error) bool {
}

func createChangesetSpec(task *Task, diff string) *ChangesetSpec {
var authorName string
var authorEmail string

if task.Template.Commit.Author == nil {
// user did not provide author info, so use defaults
authorName = "Sourcegraph"
authorEmail = "campaigns@sourcegraph.com"
} else {
authorName = task.Template.Commit.Author.Name
authorEmail = task.Template.Commit.Author.Email
}

return &ChangesetSpec{
BaseRepository: task.Repository.ID,
CreatedChangeset: &CreatedChangeset{
Expand All @@ -266,8 +278,10 @@ func createChangesetSpec(task *Task, diff string) *ChangesetSpec {
Body: task.Template.Body,
Commits: []GitCommitDescription{
{
Message: task.Template.Commit.Message,
Diff: string(diff),
Message: task.Template.Commit.Message,
AuthorName: authorName,
AuthorEmail: authorEmail,
Diff: string(diff),
},
},
Published: task.Template.Published,
Expand Down
18 changes: 18 additions & 0 deletions schema/campaign_spec.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,24 @@
"message": {
"type": "string",
"description": "The Git commit message."
},
"author": {
"title": "GitCommitAuthor",
"type": "object",
"description": "The author of the Git commit.",
"additionalProperties": false,
"required": ["name", "email"],
"properties": {
"name": {
"type": "string",
"description": "The Git commit author name."
},
"email": {
"type": "string",
"format": "email",
"description": "The Git commit author email."
}
}
}
}
},
Expand Down
36 changes: 20 additions & 16 deletions schema/campaign_spec_stringdata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.