private async Task <ForkData> FindUpstreamRepoOrUserFork(ForkMode forkMode, string userName, ForkData pullFork) { // prefer to pull and push from the same origin repo. var canUseOriginRepo = await IsPushableRepo(pullFork); if (canUseOriginRepo) { _logger.Normal($"Using upstream fork as push, for user {pullFork.Owner} at {pullFork.Uri}"); return(pullFork); } // fall back to trying a fork var userFork = await TryFindUserFork(userName, pullFork); if (userFork != null) { return(userFork); } NoPushableForkFound(forkMode, pullFork.Name); return(null); }
private async Task <ForkData> FindUserForkOrUpstream(ForkMode forkMode, string userName, ForkData pullFork) { var userFork = await TryFindUserFork(userName, pullFork); if (userFork != null) { return(userFork); } // as a fallback, we want to pull and push from the same origin repo. var canUseOriginRepo = await IsPushableRepo(pullFork); if (canUseOriginRepo) { _logger.Normal($"No fork for user {userName}. Using upstream fork for user {pullFork.Owner} at {pullFork.Uri}"); return(pullFork); } NoPushableForkFound(forkMode, pullFork.Name); return(null); }
private async Task <bool> IsPushableRepo(ForkData originFork) { var originRepo = await _gitHub.GetUserRepository(originFork.Owner, originFork.Name); return(originRepo != null && originRepo.Permissions.Push); }
public async Task <ForkData> FindPushFork(ForkMode forkMode, string userName, ForkData fallbackFork) { _logger.Detailed($"FindPushFork. Fork Mode is {forkMode}"); switch (forkMode) { case ForkMode.PreferFork: return(await FindUserForkOrUpstream(forkMode, userName, fallbackFork)); case ForkMode.PreferSingleRepository: return(await FindUpstreamRepoOrUserFork(forkMode, userName, fallbackFork)); case ForkMode.SingleRepositoryOnly: return(await FindUpstreamRepoOnly(forkMode, fallbackFork)); default: throw new ArgumentOutOfRangeException($"Unknown fork mode: {forkMode}"); } }
public RepositoryData(ForkData pull, ForkData push) { Pull = pull ?? throw new ArgumentNullException(nameof(pull)); Push = push ?? throw new ArgumentNullException(nameof(push)); Remote = "nukeeper_push"; }