private WorkingViewModel BuildWorkingViewModel(JObject body) { WorkingViewModel vm = new WorkingViewModel(); vm.action = (string)body["action"]; vm.full_name = (string)body["repository"]["full_name"]; vm.milestone_number = (int)body["milestone"]["number"]; vm.open_issues = (int)body["milestone"]["open_issues"]; string[] split = vm.full_name.Split("/"); vm.organization = split[0]; vm.repository = split[1]; return(vm); }
/// <summary> /// Update Lable for a given issue /// </summary> /// <param name="vm">IssuesConfigViewModel</param> /// <returns>Issue object</returns> public Octokit.Issue UpdateLabel(WorkingViewModel vm, string label) { //connect and build client var client = new GitHubClient(new Octokit.ProductHeaderValue(_appName)); var tokenAuth = new Credentials(_token); client.Credentials = tokenAuth; //issue we want to update IssueUpdate issueUpdate = vm.issue.ToUpdate(); //add label to issue issueUpdate.AddLabel(label); //complete update and return results var result = client.Issue.Update(vm.organization, vm.repository, vm.issue.Number, issueUpdate).Result; return(result); }
/// <summary> /// Get open issues for a milestone /// </summary> /// <param name="vm">IssuesConfigViewModel</param> /// <returns>List of open issues</returns> public IReadOnlyList <Octokit.Issue> GetOpenIssuesForMilestone(WorkingViewModel vm) { //connect to client var client = new GitHubClient(new Octokit.ProductHeaderValue(_appName)); var tokenAuth = new Credentials(_token); client.Credentials = tokenAuth; //create filter to pull just the open issues per milestone number RepositoryIssueRequest filter = new RepositoryIssueRequest { Milestone = vm.milestone_number.ToString(), State = ItemStateFilter.Open }; //fill list with results IReadOnlyList <Octokit.Issue> issues = client.Issue.GetAllForRepository(vm.organization, vm.repository, filter).Result; return(issues); }
public IActionResult Post([FromBody] JObject body) { ApiResponseViewModel response = new ApiResponseViewModel(); Request.Headers.TryGetValue("X-Hub-Signature", out StringValues signature); //check for empty signature if (string.IsNullOrEmpty(signature)) { response.Message = "Missing signature header value"; return(new StandardResponseObjectResult(response, StatusCodes.Status401Unauthorized)); } //make sure something did not go wrong if (body == null) { response.Message = "Posted object cannot be null."; return(new StandardResponseObjectResult(response, StatusCodes.Status400BadRequest)); } var payload = JsonConvert.SerializeObject(body); //check body and signature to match against secret var isGitHubPushEventAllowed = _authentication.IsValidGitHubWebHookRequest(payload, signature); //if we passed the secret check, then continue if (!isGitHubPushEventAllowed) { response.Message = "Invalid signature."; return(new StandardResponseObjectResult(response, StatusCodes.Status401Unauthorized)); } WorkingViewModel vm = this.BuildWorkingViewModel(body); //if the event action is somethign other than closed, then exit if (vm.action != "closed") { response.Success = true; response.Message = "Milestone state is open. No further action."; return(new StandardResponseObjectResult(response, StatusCodes.Status200OK)); } //if there are not open issues, then exit if (vm.open_issues == 0) { response.Success = true; response.Message = "No open issues for this milestone. No further action."; return(new StandardResponseObjectResult(response, StatusCodes.Status200OK)); } //get list of open issues for the posted milestone var list = _issuesRepo.GetOpenIssuesForMilestone(vm); //check and make sure we ahve items in the list if (list != null && list.Count > 0) { string msg = "Issues updated: "; //for each issue in the list go update the label foreach (Octokit.Issue issue in list) { vm.issue = issue; _issuesRepo.UpdateLabel(vm, "Needs Attention!"); msg += issue.Number + ","; } msg = msg.Remove(msg.Length - 1, 1); //compile final response message of successful response.Success = true; response.Message = msg; return(new StandardResponseObjectResult(response, StatusCodes.Status200OK)); } else { response.Success = true; response.Message = "No open issues found."; return(new StandardResponseObjectResult(response, StatusCodes.Status200OK)); } }
private void Button_Click(object sender, RoutedEventArgs e) { WorkingViewModel context = (WorkingViewModel)DataContext; context.Loading = Visibility.Hidden; }