Add Co-authored-by trailers to Merge's squash commit
This commit is contained in:
@@ -100,7 +100,12 @@ func (m *Manager) squashAndClose(ctx context.Context, taskID, login string) erro
|
||||
return err
|
||||
}
|
||||
|
||||
commit, err := git.SquashCommit(project.RepoPath, task.WorktreePath, project.DefaultBranch, task.MergeTitle, []string{
|
||||
coAuthors, err := m.CoAuthors(ctx, taskID, login)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commit, err := git.SquashCommit(project.RepoPath, task.WorktreePath, project.DefaultBranch, squashMessage(task.MergeTitle, coAuthors), []string{
|
||||
"GIT_AUTHOR_NAME=" + user.GitName,
|
||||
"GIT_AUTHOR_EMAIL=" + user.GitEmail,
|
||||
"GIT_COMMITTER_NAME=" + user.GitName,
|
||||
@@ -132,6 +137,35 @@ func (m *Manager) squashAndClose(ctx context.Context, taskID, login string) erro
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *Manager) CoAuthors(ctx context.Context, taskID, login string) ([]api.Participant, error) {
|
||||
participants, err := m.store.Participants(ctx, taskID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
coAuthors := []api.Participant{}
|
||||
for _, p := range participants {
|
||||
if p.Login != login {
|
||||
coAuthors = append(coAuthors, p)
|
||||
}
|
||||
}
|
||||
return coAuthors, nil
|
||||
}
|
||||
|
||||
func squashMessage(title string, coAuthors []api.Participant) string {
|
||||
trailers := []string{}
|
||||
for _, p := range coAuthors {
|
||||
if p.GitName == "" || p.GitEmail == "" {
|
||||
continue
|
||||
}
|
||||
trailers = append(trailers, fmt.Sprintf("Co-authored-by: %s <%s>", p.GitName, p.GitEmail))
|
||||
}
|
||||
if len(trailers) == 0 {
|
||||
return title
|
||||
}
|
||||
return title + "\n\n" + strings.Join(trailers, "\n")
|
||||
}
|
||||
|
||||
func (m *Manager) RemoveTask(ctx context.Context, task api.Task, project api.Project, actor string) error {
|
||||
err := m.StopTask(ctx, task.Id, actor)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user