Skip to content

Commit 4ebb7a0

Browse files
typo's, using async
minor improvements
1 parent 7d9a960 commit 4ebb7a0

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

GithubWebpagesWebhook/WebHook.cs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ public static async Task<IActionResult> Run(
2828
// Generate index html
2929
var webPage = await GenerateWebpageAsync();
3030

31-
// Copy webpages repo from github, get index.html file path
31+
// Copy webpages repo from GitHub, get index.html file path
3232
var tempLocalDirectory = Path.Combine(Path.GetTempPath(), "temp-clone-folder");
3333

3434
Directory.CreateDirectory(tempLocalDirectory);
3535

3636
var indexFilePath = await CloneWebPageRepositoryAsync(tempLocalDirectory);
3737

3838
// Update repo with new index.html
39-
File.WriteAllText(indexFilePath, webPage);
39+
await File.WriteAllTextAsync(indexFilePath, webPage);
4040

4141
// Push changes
4242
await PushChangesAsync(tempLocalDirectory);
@@ -52,7 +52,7 @@ public static async Task<IActionResult> Run(
5252
}
5353
}
5454

55-
public static async Task<string> GenerateWebpageAsync()
55+
private static async Task<string> GenerateWebpageAsync()
5656
{
5757
var template = await GetTemplateFileAsync();
5858

@@ -66,7 +66,7 @@ public static async Task<string> GenerateWebpageAsync()
6666
return htmlTemplate;
6767
}
6868

69-
public static async Task<string> GetTemplateFileAsync()
69+
private static async Task<string> GetTemplateFileAsync()
7070
{
7171
#if DEBUG
7272
return await File.ReadAllTextAsync("PageGenerator/index.html");
@@ -82,35 +82,33 @@ public static async Task<string> GetTemplateFileAsync()
8282
#endif
8383
}
8484

85-
public static async Task<string> CloneWebPageRepositoryAsync(string tempFolder)
85+
private static async Task<string> CloneWebPageRepositoryAsync(string tempFolder)
8686
{
8787
var client = new HttpClient();
8888

8989
var contents = await GithubClientWrapper.GetAllRepositoryContentAsync();
9090

91-
string indexPath = string.Empty;
91+
var indexPath = string.Empty;
9292

9393
foreach (var content in contents)
9494
{
95-
if (content.Type == Octokit.ContentType.File)
96-
{
97-
var fileBytes = await client.GetStringAsync(content.DownloadUrl);
95+
if (content.Type != ContentType.File) continue;
96+
var fileBytes = await client.GetStringAsync(content.DownloadUrl);
9897

99-
var path = Path.Combine(tempFolder, content.Name);
98+
var path = Path.Combine(tempFolder, content.Name);
10099

101-
File.WriteAllText(path, fileBytes);
100+
await File.WriteAllTextAsync(path, fileBytes);
102101

103-
if (content.Name.Contains("index.html"))
104-
{
105-
indexPath = path;
106-
}
102+
if (content.Name.Contains("index.html"))
103+
{
104+
indexPath = path;
107105
}
108106
}
109107

110108
return indexPath;
111109
}
112110

113-
public static async Task PushChangesAsync(string tempFolder)
111+
private static async Task PushChangesAsync(string tempFolder)
114112
{
115113
// Get the latest commit on the main branch
116114
var baseRef = await GithubClientWrapper.GetReferenceAsync();
@@ -120,7 +118,7 @@ public static async Task PushChangesAsync(string tempFolder)
120118
foreach (var file in Directory.GetFiles(tempFolder))
121119
{
122120
var fileName = Path.GetFileName(file);
123-
var content = File.ReadAllText(file);
121+
var content = await File.ReadAllTextAsync(file);
124122

125123
// Create a new tree entry for each file
126124
treeBuilder.Tree.Add(new NewTreeItem
@@ -132,7 +130,7 @@ public static async Task PushChangesAsync(string tempFolder)
132130
});
133131
}
134132

135-
// Finilaize the changes and push
133+
// Finalize the changes and push
136134
var newTree = await GithubClientWrapper.CreateTreeResponseAsync(treeBuilder);
137135

138136
var commit = await GithubClientWrapper.CreateCommitAsync(newTree, baseRef);

0 commit comments

Comments
 (0)