private async Task <RepoSettingsViewModel> GetRepoSettingsViewModel(string ownerId, string repoId) { if (string.IsNullOrEmpty(ownerId)) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(repoId)) { throw new ArgumentNullException(); } try { var rs = await _repoSettingsStore.GetRepoSettingsAsync(ownerId, repoId); var rsvm = new RepoSettingsViewModel(rs); return(rsvm); } catch (RepoSettingsNotFoundException) { Log.Debug("No repo settings found for repo '{0}/{1}'", ownerId, repoId); return(new RepoSettingsViewModel { OwnerId = ownerId, RepoId = repoId }); } catch (Exception e) { Log.Error(e, "Error retrieving owner settings with owner id '{0}'", ownerId); throw; } }
/// <summary> /// Check that the user has access to the org and repo then /// return the settings for that repository, create settings if none exists /// </summary> /// <param name="user"></param> /// <param name="ownerId"></param> /// <param name="repoId"></param> /// <returns></returns> public async Task <RepoSettings> CheckRepoSettingsAsync(ClaimsPrincipal user, string ownerId, string repoId) { var repo = await CheckGitHubRepository(user.Identity, ownerId, repoId); try { var repoSettings = await _repoSettingsStore.GetRepoSettingsAsync(ownerId, repoId); if (string.IsNullOrEmpty(repoSettings.CloneUrl)) { repoSettings.CloneUrl = repo.CloneUrl; await _repoSettingsStore.CreateOrUpdateRepoSettingsAsync(repoSettings); } return(repoSettings); } catch (RepoSettingsNotFoundException) { var newRepoSettings = new RepoSettings { OwnerId = ownerId, RepositoryId = repoId, CloneUrl = repo.CloneUrl, OwnerIsOrg = !user.Identity.Name.Equals(ownerId, StringComparison.InvariantCultureIgnoreCase), OwnerAvatar = repo.Owner?.AvatarUrl }; await _repoSettingsStore.CreateOrUpdateRepoSettingsAsync(newRepoSettings); return(newRepoSettings); } catch (Exception e) { Log.Error($"Error checking repo settings for '{ownerId}/{repoId}", e); throw; } }