public async Task <bool> StorePullRequestMetadata(PullRequest pr, string key, string data) { var patchDocument = new JsonPatchDocument() { new JsonPatchOperation { Operation = Operation.Add, Path = "/" + key, Value = data } }; try { var newProperties = await _gitHttpClient .UpdatePullRequestPropertiesAsync(patchDocument, pr.ProjectName, pr.RepositoryName, int.Parse(pr.Id)).ConfigureAwait(false); return(newProperties.ContainsKey(key)); } catch (VssException ex) when(ex.Message.Contains("TF401181: The pull request cannot be edited due to its state.")) { return(true); //TODO error handling: The PR is probably completed or abandoned and can no longer be updated } catch (VssException ex) when(ex.Message == "VS30063: You are not authorized to access https://dev.azure.com.") { //TODO error handling: PAT expired or missing scope "Code -> Read & Write" throw; } return(false); }
public async Task <string> GetPullRequestMetaData(PullRequest pr, string key) { var properties = await _gitHttpClient.GetPullRequestPropertiesAsync(pr.ProjectName, pr.RepositoryName, int.Parse(pr.Id)).ConfigureAwait(false); return((string)properties.FirstOrDefault(p => p.Key == key).Value); }