Browse Source

build: Handle co-authors (ref #3744) (#8708)

The authorship script didn't pick up people who were only ever
"co-authors" of a commit, such as when they wrote stuff which was later
included in a PR by someone else, or added code during code review.

This modified the script to look closer in the commit bodies for
"Co-authored-by:"-lines and adds those found to the set of authors.
Jakob Borg 2 years ago
parent
commit
09f4d865ae
3 changed files with 49 additions and 11 deletions
  1. 4 2
      AUTHORS
  2. 0 0
      gui/default/syncthing/core/aboutModalView.html
  3. 45 9
      script/authors.go

+ 4 - 2
AUTHORS

@@ -23,6 +23,7 @@ Alessandro G. (alessandro.g89) <[email protected]>
 Alex Lindeman <[email protected]>
 Alex Xu <[email protected]>
 Alexander Graf (alex2108) <[email protected]>
+Alexandre Alves <[email protected]>
 Alexandre Viau (aviau) <[email protected]> <[email protected]>
 Aman Gupta <[email protected]>
 Anderson Mesquita (andersonvom) <[email protected]>
@@ -101,7 +102,7 @@ Elias Jarlebring (jarlebring) <[email protected]>
 Elliot Huffman <[email protected]>
 Emil Hessman (ceh) <[email protected]>
 Eng Zer Jun <[email protected]>
-entity0xfe <[email protected]>
+entity0xfe <[email protected]> <[email protected]>
 Eric Lesiuta <[email protected]>
 Eric P <[email protected]>
 Erik Meitner (WSGCSysadmin) <[email protected]>
@@ -146,6 +147,7 @@ Jaroslav Malec (dzarda) <[email protected]>
 jaseg <[email protected]>
 Jauder Ho <[email protected]>
 Jaya Chithra (jayachithra) <[email protected]>
+Jaya Kumar <[email protected]>
 Jeffery To <[email protected]>
 jelle van der Waa <[email protected]>
 Jens Diemer (jedie) <[email protected]> <[email protected]>
@@ -267,7 +269,7 @@ Sacheendra Talluri (sacheendra) <[email protected]>
 Scott Klupfel (kluppy) <[email protected]>
 sec65 <[email protected]>
 Sergey Mishin (ralder) <[email protected]>
-Shaarad Dalvi <[email protected]>
+Shaarad Dalvi <[email protected]> <[email protected]>
 Simon Frei (imsodin) <[email protected]>
 Simon Mwepu <[email protected]>
 Sly_tom_cat <[email protected]>

File diff suppressed because it is too large
+ 0 - 0
gui/default/syncthing/core/aboutModalView.html


+ 45 - 9
script/authors.go

@@ -235,27 +235,63 @@ var excludeCommits = stringSetFromStrings([]string{
 // allAuthors returns the set of authors in the git commit log, except those
 // in excluded commits.
 func allAuthors() map[string]string {
-	args := append([]string{"log", "--format=%H %ae %an"})
+	// Format is hash, email, name, newline, body. The body is indented with
+	// one space, to differentiate from the hash lines.
+	args := append([]string{"log", "--format=%H %ae %an%n%w(,1,1)%b"})
 	cmd := exec.Command("git", args...)
 	bs, err := cmd.Output()
 	if err != nil {
 		log.Fatal("git:", err)
 	}
 
+	coAuthoredPrefix := "Co-authored-by: "
 	names := make(map[string]string)
+	skipCommit := false
 	for _, line := range bytes.Split(bs, []byte{'\n'}) {
-		fields := strings.SplitN(string(line), " ", 3)
-		if len(fields) != 3 {
+		if len(line) == 0 {
 			continue
 		}
-		hash, email, name := fields[0], fields[1], fields[2]
 
-		if excludeCommits.has(hash) {
-			continue
-		}
+		switch line[0] {
+		case ' ':
+			// Look for Co-authored-by: lines in the commit body.
+			if skipCommit {
+				continue
+			}
+
+			line = line[1:]
+			if bytes.HasPrefix(line, []byte(coAuthoredPrefix)) {
+				// Co-authored-by: Name Name <[email protected]>
+				line = line[len(coAuthoredPrefix):]
+				if name, email, ok := strings.Cut(string(line), "<"); ok {
+					name = strings.TrimSpace(name)
+					email = strings.Trim(strings.TrimSpace(email), "<>")
+					if email == "@" {
+						// GitHub special for users who hide their email.
+						continue
+					}
+					if names[email] == "" {
+						names[email] = name
+					}
+				}
+			}
 
-		if names[email] == "" {
-			names[email] = name
+		default: // hash email name
+			fields := strings.SplitN(string(line), " ", 3)
+			if len(fields) != 3 {
+				continue
+			}
+			hash, email, name := fields[0], fields[1], fields[2]
+
+			if excludeCommits.has(hash) {
+				skipCommit = true
+				continue
+			}
+			skipCommit = false
+
+			if names[email] == "" {
+				names[email] = name
+			}
 		}
 	}
 

Some files were not shown because too many files changed in this diff