-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented a user-triggered rebase feature
Co-Authored-By: Sigrun Arna Sigurdardottir <sasig@kth.se> Co-Authored-By: Javier Ron <javierron90@gmail.com>
- Loading branch information
Showing
17 changed files
with
717 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace CompressImagesFunction | ||
{ | ||
public partial class CompressionResult | ||
{ | ||
public static CompressionResult[] ParseCommitMessage(string commitBody) | ||
{ | ||
try | ||
{ | ||
var compressionResults = new List<CompressionResult>(); | ||
|
||
var commitLines = commitBody.Split(new[] { '\r', '\n' }); | ||
for (var i = 0; i < commitLines.Length; i++) | ||
{ | ||
if (i == 0 || string.IsNullOrWhiteSpace(commitLines[i])) | ||
{ | ||
// skip the first line and blank lines | ||
continue; | ||
} | ||
|
||
if (commitLines[i].StartsWith("Signed-off-by:") || commitLines[i].StartsWith("*Total --")) | ||
{ | ||
// skip the DCO line | ||
continue; | ||
} | ||
|
||
var pattern = @"\*?(.*) -- (.*)kb -> (.*)kb \((.*)%\)"; | ||
var capture = Regex.Matches(commitLines[i], pattern)[0]; | ||
|
||
compressionResults.Add(new CompressionResult | ||
{ | ||
Title = capture.Groups[1].Value, | ||
SizeBefore = Convert.ToDouble(capture.Groups[2].Value), | ||
SizeAfter = Convert.ToDouble(capture.Groups[3].Value), | ||
}); | ||
} | ||
|
||
return compressionResults.ToArray(); | ||
} | ||
catch | ||
{ | ||
// commit messages can be out of our control | ||
return null; | ||
} | ||
} | ||
|
||
public static CompressionResult[] Merge(CompressionResult[] newOptimizedImages, CompressionResult[] previousCommitResults) | ||
{ | ||
List<CompressionResult> list = new List<CompressionResult>(); | ||
list.AddRange(newOptimizedImages); | ||
list.AddRange(previousCommitResults); | ||
|
||
var nonRepeat = list.GroupBy(x => x.Title).Select(y => y.First()); | ||
|
||
return nonRepeat.ToArray(); | ||
} | ||
|
||
public static CompressionResult[] Filter(CompressionResult[] optimizedImages, string[] toRemove) | ||
{ | ||
var relativePaths = toRemove.Select(path => Path.GetFileName(path)); | ||
var filtered = optimizedImages.Where(r => !relativePaths.Contains(r.Title)); | ||
return filtered.ToArray(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.