Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

695b include user in git commit #735

Merged
merged 2 commits into from
Sep 14, 2017

Conversation

tamarakaufler
Copy link
Contributor

No description provided.

func commit(ctx context.Context, workingDir, commitMessage string) error {
func commit(ctx context.Context, workingDir string, commitAction *CommitAction) error {
commitAuthor := commitAction.Author
// The user in the update.Cause.User must be a valid github user, otherwise the commit fails

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

// then this is just about ok. Otherwise there could be config file with stored users to ignore etc.
// Currently the committer is hardcoded to flux-bot for user requested actions.
// TODO (potentially): allow the users to set the committer, ie have an additional
// update.Cause.Committer field.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

// Currently the committer is hardcoded to flux-bot for user requested actions.
// TODO (potentially): allow the users to set the committer, ie have an additional
// update.Cause.Committer field.
if commitAuthor != "" && commitAuthor != "test@test" {

This comment was marked as abuse.

return errors.Wrap(err, "git commit config")
}
if err := execGitCmd(ctx,
workingDir, nil, nil,

This comment was marked as abuse.

This comment was marked as abuse.

daemon/daemon.go Outdated
@@ -96,7 +97,7 @@ func (d *Daemon) ListServices(namespace string) ([]flux.ServiceStatus, error) {
return res, nil
}

// List the images available for set of services
// ListImages - List the images available for set of services

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

Copy link
Member

@squaremo squaremo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good. I've suggested some tidies. I'm going to try it out now :)

cmd.Flags().StringVarP(&opts.Message, "message", "m", "", "attach a message to the update")
cmd.Flags().StringVar(&opts.User, "user", username, "override the user reported as initating the update")
cmd.Flags().StringVar(&opts.User, "user", username, "override the user reported as initiating the update")

This comment was marked as abuse.

This comment was marked as abuse.

authorInfo := getUserGitconfig()
userName := authorInfo["user.name"]

switch userName {

This comment was marked as abuse.

This comment was marked as abuse.

userGitconfig["user.email"] = ""
return userGitconfig
}
res := out.String()

This comment was marked as abuse.

func userGitconfigMap(s string) map[string]string {
c := make(map[string]string)
lines := splitList(s)
if len(lines) == 0 {

This comment was marked as abuse.

This comment was marked as abuse.

}
userGitconfig["user.name"] = username
userGitconfig["user.email"] = ""
return userGitconfig

This comment was marked as abuse.

gitPath = fs.String("git-path", "", "path within git repo to locate Kubernetes manifests (relative path)")
gitUser = fs.String("git-user", "Weave Flux", "username to use as git committer")
gitEmail = fs.String("git-email", "support@weave.works", "email to use as git committer")
gitSetAuthor = fs.Bool("git-set-author", false, "boolean to set a git author different to git committer")

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

daemon/daemon.go Outdated
@@ -511,3 +525,10 @@ func policyEventTypes(u policy.Update) []string {
sort.Strings(result)
return result
}

func getCommitAuthor(setAuthor bool, author string) string {

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

@squaremo
Copy link
Member

image

userName := authorInfo["user.name"]
userEmail := authorInfo["user.email"]

switch userName {

This comment was marked as abuse.


userGitconfigInfo := userGitconfigMap(d)
if len(userGitconfigInfo) != 6 {
t.Fatal("expected no content")

This comment was marked as abuse.

gitPath = fs.String("git-path", "", "path within git repo to locate Kubernetes manifests (relative path)")
gitUser = fs.String("git-user", "Weave Flux", "username to use as git committer")
gitEmail = fs.String("git-email", "support@weave.works", "email to use as git committer")
gitSetAuthor = fs.Bool("git-set-author", false, "If set, the author of git commits will reflect the user who initiated the commit and will differ from the git committer.")

This comment was marked as abuse.

Copy link
Member

@squaremo squaremo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go 🏅
Thanks for sticking at it!

@squaremo
Copy link
Member

(Please rebase -i or squash before/while merging)

Refactored with fluxd set-author-flag
@tamarakaufler tamarakaufler force-pushed the 695b-include-user-in-git-commit branch from 54b81f2 to 366fd04 Compare September 13, 2017 15:55
@tamarakaufler tamarakaufler merged commit 953c51c into master Sep 14, 2017
@tamarakaufler tamarakaufler deleted the 695b-include-user-in-git-commit branch September 14, 2017 07:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants