Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update commit to agree with DCO (fixes #348) #445

Merged
merged 2 commits into from
Jul 21, 2019
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
3 changes: 3 additions & 0 deletions CompressImagesFunction/CommitMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public static string Create(CompressionResult[] optimizedImages)

commitMessage.Append(imageLog);

commitMessage.AppendLine();
commitMessage.AppendLine($"Signed-off-by: {KnownGitHubs.ImgBotLogin} <{KnownGitHubs.ImgBotEmail}>");

return commitMessage.ToString();
}

Expand Down
6 changes: 6 additions & 0 deletions OpenPrFunction/Stats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public static ImageStat[] ParseStats(string commitBody)
continue;
}

if (commitLines[i].StartsWith("Signed-off-by:"))
{
// skip the DCO line
continue;
}

var pattern = @"\*?(.*) -- (.*) -> (.*) \((.*)%\)";
var capture = Regex.Matches(commitLines[i], pattern)[0];

Expand Down
16 changes: 12 additions & 4 deletions Test/CommitMessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public void GivenImages_ShouldReportEach()
"*Total -- 600.69kb -> 455.92kb (24.1%)" + Environment.NewLine +
Environment.NewLine +
"path/to/image2.png -- 500.32kb -> 360.13kb (28.02%)" + Environment.NewLine +
"path/to/image.png -- 100.37kb -> 95.79kb (4.56%)" + Environment.NewLine;
"path/to/image.png -- 100.37kb -> 95.79kb (4.56%)" + Environment.NewLine +
Environment.NewLine +
"Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>" + Environment.NewLine;

Assert.AreEqual(expectedMessage, message);
}
Expand All @@ -56,7 +58,9 @@ public void GivenOneImage_ShouldReportSingleImageNoTotal()

var expectedMessage = KnownGitHubs.CommitMessageTitle + Environment.NewLine +
Environment.NewLine +
"path/to/image.png -- 100.30kb -> 95.70kb (4.59%)" + Environment.NewLine;
"path/to/image.png -- 100.30kb -> 95.70kb (4.59%)" + Environment.NewLine +
Environment.NewLine +
"Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>" + Environment.NewLine;

Assert.AreEqual(expectedMessage, message);
}
Expand Down Expand Up @@ -87,7 +91,9 @@ public void GivenBackslashes_ShouldRenderForwardSlashes()
"*Total -- 501.89kb -> 455.68kb (9.21%)" + Environment.NewLine +
Environment.NewLine +
"path/to/image2.png -- 300.92kb -> 260.56kb (13.41%)" + Environment.NewLine +
"path/to/image.png -- 200.97kb -> 195.12kb (2.91%)" + Environment.NewLine;
"path/to/image.png -- 200.97kb -> 195.12kb (2.91%)" + Environment.NewLine +
Environment.NewLine +
"Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>" + Environment.NewLine;

Assert.AreEqual(expectedMessage, message);
}
Expand Down Expand Up @@ -118,7 +124,9 @@ public void GivenUnderscorePrefix_ShouldRenderUnderscore()
"*Total -- 501.89kb -> 455.68kb (9.21%)" + Environment.NewLine
+ Environment.NewLine +
"path/to/image2.png -- 300.92kb -> 260.56kb (13.41%)" + Environment.NewLine +
"path/to/_image.png -- 200.97kb -> 195.12kb (2.91%)" + Environment.NewLine;
"path/to/_image.png -- 200.97kb -> 195.12kb (2.91%)" + Environment.NewLine +
Environment.NewLine +
"Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>" + Environment.NewLine;

Assert.AreEqual(expectedMessage, message);
}
Expand Down
50 changes: 46 additions & 4 deletions Test/PullRequestBodyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public void GivenMultiImageCommitMessage_ShouldFormatMarkdownTable()
Environment.NewLine +
"/featurecard.png -- 542.34kb -> 86.13kb (84.12%)" + Environment.NewLine +
"/graph.png -- 148.78kb -> 88.71kb (40.38%)" + Environment.NewLine +
"/featured-marketplace.png -- 163.11kb -> 133.44kb (18.19%)" + Environment.NewLine;
"/featured-marketplace.png -- 163.11kb -> 133.44kb (18.19%)" + Environment.NewLine +
Environment.NewLine +
"Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>" + Environment.NewLine;

var expectedMarkdown = "## Beep boop. Your images are optimized!" + Environment.NewLine +
Environment.NewLine +
Expand Down Expand Up @@ -56,7 +58,9 @@ public void GivenZeroPercentReductionCommitMessage_ShouldOmitPercentage()
{
var commitMessage = "[ImgBot] Optimize images" + Environment.NewLine +
Environment.NewLine +
"/featured-marketplace.png -- 163.11kb -> 160.11kb (0.02%)" + Environment.NewLine;
"/featured-marketplace.png -- 163.11kb -> 160.11kb (0.02%)" + Environment.NewLine +
Environment.NewLine +
"Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>" + Environment.NewLine;

var expectedMarkdown = "## Beep boop. Your images are optimized!" + Environment.NewLine +
Environment.NewLine +
Expand All @@ -82,7 +86,9 @@ public void GivenReductionBelow5PercentCommitMessage_ShouldOmitPercentage()
{
var commitMessage = "[ImgBot] Optimize images" + Environment.NewLine +
Environment.NewLine +
"/featured-marketplace.png -- 163.11kb -> 155.11kb (4.40%)" + Environment.NewLine;
"/featured-marketplace.png -- 163.11kb -> 155.11kb (4.40%)" + Environment.NewLine +
Environment.NewLine +
"Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>" + Environment.NewLine;

var expectedMarkdown = "## Beep boop. Your images are optimized!" + Environment.NewLine +
Environment.NewLine +
Expand All @@ -108,7 +114,9 @@ public void GivenSingleImageCommitMessage_ShouldFormatMarkdownTable()
{
var commitMessage = "[ImgBot] Optimize images" + Environment.NewLine +
Environment.NewLine +
"/featured-marketplace.png -- 163.11kb -> 133.44kb (18.19%)" + Environment.NewLine;
"/featured-marketplace.png -- 163.11kb -> 133.44kb (18.19%)" + Environment.NewLine +
Environment.NewLine +
"Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>" + Environment.NewLine;

var expectedMarkdown = "## Beep boop. Your images are optimized!" + Environment.NewLine +
Environment.NewLine +
Expand Down Expand Up @@ -156,5 +164,39 @@ public void GivenSingleLineGarbageCommitMessage_ShouldRenderDefaultPrBody()

Assert.AreEqual(expectedMarkdown, result);
}

[TestMethod]
public void GivenMissingDCOCommitMessage_ShouldFormatMarkdownTable()
{
var commitMessage = "[ImgBot] Optimize images" + Environment.NewLine +
Environment.NewLine +
"*Total -- 854.23kb -> 308.28kb (63.91%)" + Environment.NewLine +
Environment.NewLine +
"/featurecard.png -- 542.34kb -> 86.13kb (84.12%)" + Environment.NewLine +
"/graph.png -- 148.78kb -> 88.71kb (40.38%)" + Environment.NewLine +
"/featured-marketplace.png -- 163.11kb -> 133.44kb (18.19%)" + Environment.NewLine;

var expectedMarkdown = "## Beep boop. Your images are optimized!" + Environment.NewLine +
Environment.NewLine +
"Your image file size has been reduced by **64%** 🎉" + Environment.NewLine +
Environment.NewLine +
"<details>" + Environment.NewLine +
"<summary>" + Environment.NewLine +
"Details" + Environment.NewLine +
"</summary>" + Environment.NewLine +
Environment.NewLine +
"| File | Before | After | Percent reduction |" + Environment.NewLine +
"|:--|:--|:--|:--|" + Environment.NewLine +
"| /featurecard.png | 542.34kb | 86.13kb | 84.12% |" + Environment.NewLine +
"| /graph.png | 148.78kb | 88.71kb | 40.38% |" + Environment.NewLine +
"| /featured-marketplace.png | 163.11kb | 133.44kb | 18.19% |" + Environment.NewLine +
"| | | | |" + Environment.NewLine +
"| **Total :** | **854.23kb** | **308.28kb** | **63.91%** |" + Environment.NewLine +
"</details>" + expectedFooter;

var result = PullRequestBody.Generate(Stats.ParseStats(commitMessage));

Assert.AreEqual(expectedMarkdown, result);
}
}
}