Commit 47e62867 authored by Martin Lowe's avatar Martin Lowe 🇨🇦 Committed by Christopher Guindon
Browse files

Allow for multiple Signed-off-by footer lines to exist in commits



CommitHelper now checks multiple footerlines for matching email rather
than first only.
Signed-off-by: Martin Lowe's avatarMartin Lowe <martin.lowe@eclipse-foundation.org>
parent 598e0555
......@@ -56,18 +56,20 @@ public class CommitHelper {
* processing the body and parsing out the given footer knowing its format.
*
* @param c the commit to retrieve the signed off by footer for
* @return the email address in the Signed-off-by footer, or null if none could
* be found.
* @return true if an email address matching the authors was found in the signed-off by footer lines
*/
public static String getSignedOffByEmail(Commit c) {
public static boolean getSignedOffByEmail(Commit c) {
if (c == null) {
return null;
return false;
}
Matcher m = SIGNED_OFF_BY_FOOTER.matcher(c.getBody());
if (m.find()) {
return m.group(2);
while (m.find()) {
String signOffEmail = m.group(2);
if (signOffEmail != null && signOffEmail.equalsIgnoreCase(c.getAuthor().getMail())) {
return true;
}
}
return null;
return false;
}
private CommitHelper() {
......
......@@ -227,9 +227,8 @@ public class ValidationResource {
addError(r, "An Eclipse Contributor Agreement is required.", c.getHash());
}
// retrieve the email of the Signed-off-by footer
String signedOffBy = CommitHelper.getSignedOffByEmail(c);
if (signedOffBy != null && signedOffBy.equalsIgnoreCase(eclipseAuthor.getMail())) {
// check if one of the signed off by footer lines matches the author email.
if (CommitHelper.getSignedOffByEmail(c)) {
addMessage(r, "The author has signed-off on the contribution.", c.getHash());
} else {
addMessage(
......
......@@ -26,14 +26,14 @@ import io.quarkus.test.junit.QuarkusTest;
*
*/
@QuarkusTest
public class CommitHelperTest {
class CommitHelperTest {
// represents a known good commit before the start of each test
GitUser testUser;
Commit baseCommit;
@BeforeEach
public void setup() {
void setup() {
// basic good user
testUser = new GitUser();
testUser.setMail("test.user@eclipse-foundation.org");
......@@ -52,71 +52,84 @@ public class CommitHelperTest {
}
@Test
public void getSignedOffByEmailNullCommit() {
Assertions.assertNull(CommitHelper.getSignedOffByEmail(null), "Expected null return for null commit");
void getSignedOffByEmailNullCommit() {
Assertions.assertFalse(CommitHelper.getSignedOffByEmail(null), "Expected null return for null commit");
}
@Test
public void getSignedOffByEmailOnlyFooter() {
void getSignedOffByEmailOnlyFooter() {
baseCommit.setBody(String.format("Signed-off-by: %s <%s>", testUser.getName(), testUser.getMail()));
String actualMail = CommitHelper.getSignedOffByEmail(baseCommit);
Assertions.assertEquals(testUser.getMail(), actualMail);
boolean actual = CommitHelper.getSignedOffByEmail(baseCommit);
Assertions.assertTrue(actual);
}
@Test
void getSignedOffByEmailWithDifferentCasing() {
baseCommit.setBody(String.format("Signed-off-by: %s <%s>", testUser.getName(), testUser.getMail().toUpperCase()));
boolean actual = CommitHelper.getSignedOffByEmail(baseCommit);
Assertions.assertTrue(actual);
}
@Test
public void getSignedOffByEmailBodyAndFooter() {
void getSignedOffByEmailBodyAndFooter() {
baseCommit.setBody(
String.format("Sample body content\n\nSigned-off-by: %s <%s>", testUser.getName(), testUser.getMail()));
String actualMail = CommitHelper.getSignedOffByEmail(baseCommit);
Assertions.assertEquals(testUser.getMail(), actualMail);
boolean actualMail = CommitHelper.getSignedOffByEmail(baseCommit);
Assertions.assertTrue(actualMail);
}
@Test
public void getSignedOffByEmailNoNameFooter() {
void getSignedOffByEmailNoNameFooter() {
baseCommit.setBody(
String.format("Sample body content\n\nSigned-off-by:<%s>", testUser.getMail()));
String actualMail = CommitHelper.getSignedOffByEmail(baseCommit);
Assertions.assertEquals(testUser.getMail(), actualMail);
boolean actual = CommitHelper.getSignedOffByEmail(baseCommit);
Assertions.assertTrue(actual);
}
@Test
public void getSignedOffByEmailNoBrackets() {
void getSignedOffByEmailNoBrackets() {
baseCommit.setBody(
String.format("Sample body content\n\nSigned-off-by:%s", testUser.getMail()));
String actualMail = CommitHelper.getSignedOffByEmail(baseCommit);
Assertions.assertNull(actualMail);
boolean actual = CommitHelper.getSignedOffByEmail(baseCommit);
Assertions.assertFalse(actual);
}
@Test
public void getSignedOffByEmailBadFooterName() {
void getSignedOffByEmailBadFooterName() {
baseCommit.setBody(
String.format("Sample body content\n\nSign-off-by: %s <%s>", testUser.getName(), testUser.getMail()));
Assertions.assertNull(CommitHelper.getSignedOffByEmail(baseCommit), "Expected no result with typo in footer name");
Assertions.assertFalse(CommitHelper.getSignedOffByEmail(baseCommit), "Expected false with typo in footer name");
baseCommit.setBody(
String.format("Sample body content\n\nSIGNED-OFF-BY: %s <%s>", testUser.getName(), testUser.getMail()));
Assertions.assertNull(CommitHelper.getSignedOffByEmail(baseCommit), "Expected no result with bad casing");
Assertions.assertFalse(CommitHelper.getSignedOffByEmail(baseCommit), "Expected false with bad casing");
}
@Test
void getSignedOffByEmailBadAuthorEmail() {
baseCommit.setBody(
String.format("Sample body content\n\nSigned-off-by: %s <%s>", testUser.getName(), "known_bad@email.org"));
Assertions.assertFalse(CommitHelper.getSignedOffByEmail(baseCommit), "Expected false with typo in footer name");
}
@Test
public void validateCommitKnownGood() {
void validateCommitKnownGood() {
Assertions.assertTrue(CommitHelper.validateCommit(baseCommit), "Expected basic commit to pass validation");
}
@Test
public void validateCommitNullCommit() {
void validateCommitNullCommit() {
Assertions.assertFalse(CommitHelper.validateCommit(null), "Expected null commit to fail validation");
}
@Test
public void validateCommitNoAuthor() {
void validateCommitNoAuthor() {
baseCommit.setAuthor(null);
Assertions.assertFalse(CommitHelper.validateCommit(baseCommit),
"Expected basic commit to fail validation w/ no author");
}
@Test
public void validateCommitNoAuthorMail() {
void validateCommitNoAuthorMail() {
GitUser noMail = new GitUser();
noMail.setName("Some Name");
......@@ -126,14 +139,14 @@ public class CommitHelperTest {
}
@Test
public void validateCommitNoCommitter() {
void validateCommitNoCommitter() {
baseCommit.setCommitter(null);
Assertions.assertFalse(CommitHelper.validateCommit(baseCommit),
"Expected basic commit to fail validation w/ no committer");
}
@Test
public void validateCommitNoCommitterMail() {
void validateCommitNoCommitterMail() {
GitUser noMail = new GitUser();
noMail.setName("Some Name");
......@@ -143,28 +156,28 @@ public class CommitHelperTest {
}
@Test
public void validateCommitNoHash() {
void validateCommitNoHash() {
baseCommit.setHash(null);
Assertions.assertFalse(CommitHelper.validateCommit(baseCommit),
"Expected basic commit to fail validation w/ no commit hash");
}
@Test
public void validateCommitNoBody() {
void validateCommitNoBody() {
baseCommit.setBody(null);
Assertions.assertTrue(CommitHelper.validateCommit(baseCommit),
"Expected basic commit to pass validation w/ no body");
}
@Test
public void validateCommitNoParents() {
void validateCommitNoParents() {
baseCommit.setParents(new ArrayList<>());
Assertions.assertTrue(CommitHelper.validateCommit(baseCommit),
"Expected basic commit to pass validation w/ no parents");
}
@Test
public void validateCommitNoSubject() {
void validateCommitNoSubject() {
baseCommit.setSubject(null);
Assertions.assertTrue(CommitHelper.validateCommit(baseCommit),
"Expected basic commit to pass validation w/ no subject");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment