-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhraseReplacer.cs
32 lines (28 loc) · 1.12 KB
/
PhraseReplacer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.IO;
using System.Threading.Tasks;
namespace LicenseMe;
public static class PhraseReplacer
{
/// <summary>
/// Replaces the License-Text with the changed License
/// </summary>
/// <param name="directory">The Directory that has recieved a new license</param>
public static async Task InsertLicenseToReadme(GitDirectory directory)
{
if (!directory.HasReadme)
{
await directory.AddReadme();
}
var file = await File.ReadAllTextAsync(directory.ReadmePath);
foreach (var section in file.Split("## "))
{
if (section.StartsWith("License") || section.StartsWith("license") || section.StartsWith("LICENSE"))
{
var advancedInformation = await directory.LicenseType?.GetAdvancedLicenseInformation();
file = file.Replace(section, $"License\n\nThis project is licensed under the [{advancedInformation.Name}]({advancedInformation.HtmlUrl}) - see the [LICENSE](LICENSE) file for details\n\n##");
}
}
await File.WriteAllTextAsync(directory.ReadmePath, file);
}
}