Skip to content

Commit

Permalink
Maybe don't fire dev update if there is no update.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sora-yx committed Dec 18, 2024
1 parent f26e1a6 commit 425a0b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 40 deletions.
14 changes: 9 additions & 5 deletions SA-Mod-Manager/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,20 @@ private async Task InitUriAsync(string[] args, bool alreadyRunning)
}


public static async Task<(bool, WorkflowRunInfo, GitHubArtifact, string)> GetArtifact()
public static async Task<(bool, WorkflowRunInfo, GitHubArtifact)> GetArtifact()
{
Debugger.Launch();

var workflowRun = await GitHub.GetLatestWorkflowRun();

if (workflowRun is null)
return (false, null, null, null);
return (false, null, null);


bool hasUpdate = RepoCommit != workflowRun.HeadSHA;

if (hasUpdate == false)
return (false, null, null);


GitHubAction latestAction = await GitHub.GetLatestAction();
GitHubArtifact info = null;
Expand All @@ -332,7 +336,7 @@ private async Task InitUriAsync(string[] args, bool alreadyRunning)
}
}

return (hasUpdate, workflowRun, info, "Changelog are currently not available for dev version.\n");
return (hasUpdate, workflowRun, info);
}

public static async Task<bool> PerformDevUpdateManagerCheck()
Expand All @@ -341,7 +345,7 @@ public static async Task<bool> PerformDevUpdateManagerCheck()
var update = await App.GetArtifact();
if (update.Item2 is not null)
{
string changelog = await GitHub.GetGitChangeLog(update.Item4);
string changelog = await GitHub.GetGitChangeLog(update.Item2.HeadSHA);
var manager = new InfoManagerUpdate(changelog, "Dev");
manager.ShowDialog();

Expand Down
49 changes: 14 additions & 35 deletions SA-Mod-Manager/Updater/GitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ private static async Task<string> GetSHAFromLastTag(GitHubRelease release, HttpC
{
string pattern = @"^\w+\s+"; // This regular expression matches any word followed by one or more spaces at the beginning of the string.
string result = Regex.Replace(version, pattern, "").Trim();

}
catch
{
Expand Down Expand Up @@ -482,7 +482,7 @@ private static async Task<string> GetSHAFromLastTag(GitHubRelease release, HttpC
{
throw new Exception("Couldn't check version difference, update won't work.");
}


return (hasUpdate, sha, targetAsset, version);
}
Expand All @@ -503,51 +503,30 @@ public static async Task<string> GetGitChangeLog(string hash)

// string apiUrl = $"https://api.github.com/repos/{owner}/{repo}/commits?sha={hash}&per_page=100&sha={branch}";

bool isEmpty = string.IsNullOrEmpty(App.RepoCommit); //empty means we are on dev version
string apiUrl = isEmpty == false ? $"https://api.github.com/repos/{owner}/{repo}/compare/{App.RepoCommit}...{hash[..7]}" : $"https://api.github.com/repos/{owner}/{repo}/commits?sha={hash}&per_page=100&sha={branch}";

string apiUrl = $"https://api.github.com/repos/{owner}/{repo}/compare/{App.RepoCommit}...{hash[..7]}";

HttpResponseMessage response = await httpClient.GetAsync(apiUrl);
string text = "";
string text = "No changelog found";

if (response.IsSuccessStatusCode)
{
text = "";
string jsonResult = await response.Content.ReadAsStringAsync();

if (isEmpty) //if we are on dev version get the last 100 commits
{
var info = JsonConvert.DeserializeObject<GHCommitInfo[]>(jsonResult);

int limit = info.ToList().FindIndex(t => t.SHA == App.RepoCommit);
if (limit == -1)
limit = info.Length;

for (int i = 0; i < limit; ++i)
{
if (info[i].Commit.IsSkipCI())
continue;

string message = info[i].Commit.Message.Replace("\r", "");
if (message.Contains("\n"))
message = message[..message.IndexOf("\n", StringComparison.Ordinal)];
var info = JsonConvert.DeserializeObject<CommitComparisonResponse>(jsonResult);

string author = info[i].Commit.Author.Name;
text += $" - {message} - {author}\n";
}
}
else //get all the commits between new version and current version
foreach (var commit in info.commits)
{
var info = JsonConvert.DeserializeObject<CommitComparisonResponse>(jsonResult);

foreach (var commit in info.commits)
{
//we skip the message "merge branch master" thing as the end user wouldn't understand
if (commit.commit.message.Contains("Merge branch") && text.Length > 5)
continue;
//we skip the message "merge branch master" thing as the end user wouldn't understand
if (commit.commit.message.Contains("Merge branch") && text.Length > 5)
continue;

string author = commit.commit.author?.name ?? "Unknown";
text += $" - {commit.commit.message} - {author}\n";
}
string author = commit.commit.author?.name ?? "Unknown";
text += $" - {commit.commit.message} - {author}\n";
}

}

return text;
Expand Down

0 comments on commit 425a0b5

Please sign in to comment.