Skip to content
Merged
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
23 changes: 21 additions & 2 deletions src/WingetCreateCore/Common/GitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ namespace Microsoft.WingetCreateCore.Common
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Jose;
using Microsoft.WingetCreateCore.Common.Exceptions;
Expand Down Expand Up @@ -483,8 +486,24 @@ private async Task UpdateForkedRepoWithUpstreamCommits(Repository forkedRepo)
throw new NonFastForwardException(commitsAheadBy);
}

var upstreamBranchReference = await this.github.Git.Reference.Get(upstream.Id, $"heads/{upstream.DefaultBranch}");
await this.github.Git.Reference.Update(forkedRepo.Id, $"heads/{forkedRepo.DefaultBranch}", new ReferenceUpdate(upstreamBranchReference.Object.Sha));
// Octokit .NET doesn't support sync fork endpoint, so we make a direct call to the GitHub API.
Comment thread
AmelBawa-msft marked this conversation as resolved.
// Tracking issue for the request: https://github.com/octokit/octokit.net/issues/2989
// API reference: https://docs.github.com/en/rest/branches/branches?apiVersion=2022-11-28#sync-a-fork-branch-with-the-upstream-repository
HttpClient httpClient = new HttpClient();

// Headers
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", this.github.Credentials.Password);
httpClient.DefaultRequestHeaders.Add("Accept", "application/vnd.github+json");
httpClient.DefaultRequestHeaders.Add("X-GitHub-Api-Version", "2022-11-28");
httpClient.DefaultRequestHeaders.UserAgent.TryParseAdd(Constants.ProgramName);

// Payload
JsonObject jsonObject = new JsonObject { { "branch", forkedRepo.DefaultBranch } };
var content = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json");

var url = $"https://api.github.com/repos/{forkedRepo.Owner.Login}/{forkedRepo.Name}/merge-upstream";
var response = await httpClient.PostAsync(url, content);
response.EnsureSuccessStatusCode();
Comment thread
mdanish-kh marked this conversation as resolved.
}
}

Expand Down