Ejemplo n.º 1
0
        // GET: Issues/Edit/5
        public ActionResult Edit(int?id)
        {
            string userID = User.Identity.GetUserId();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Issue issue = db.Issues.Find(id);

            if (issue == null)
            {
                return(HttpNotFound());
            }
            if (issue.ReporterID != userID && !this.db.HasProjectRole(issue.ProjectID, userID, Role.Manager))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            IssueCreate viewModel = getCreateModel();

            viewModel.Title       = issue.Title;
            viewModel.ProjectID   = issue.ProjectID;
            viewModel.IssueID     = issue.IssueID;
            viewModel.Description = issue.Description;
            return(View("Create", viewModel));
        }
Ejemplo n.º 2
0
        public Task CreateIssue(int pProjectId, String pTitle, String pBody, String pAuthor = "Anonymous")
        {
            //check for null author
            if (String.IsNullOrWhiteSpace(pAuthor))
            {
                pAuthor = "Anonymous";
            }

            IssueCreate issue = new IssueCreate()
            {
                Description = $"**_The issue was submitted by {pAuthor} via API**.\n\n {pBody}",
                Title       = pTitle,
                ProjectId   = pProjectId,
                Labels      = "Bug-Report"
            };
            var task = _client.Issues.CreateAsync(issue);

            task.ContinueWith(t =>
            {
                Console.WriteLine($"Issue with ID {t.Result.IssueId} has been created.");
            }, TaskContinuationOptions.OnlyOnRanToCompletion);
            task.ContinueWith(t =>
            {
                if (t.Exception != null)
                {
                    Console.WriteLine($"Issue could not be created. Reason: {t.Exception.Message}");
                }
            }, TaskContinuationOptions.OnlyOnFaulted);

            return(task);
        }
Ejemplo n.º 3
0
        private IssueCreate getCreateModel()
        {
            IssueCreate viewModel = new IssueCreate();

            viewModel.SelectableProjects = this.db.GetProjectsForUser(User.Identity.GetUserId())
                                           .ToList()
                                           .Select(p => new KeyValuePair <object, string>(p.ProjectID, p.Name));
            return(viewModel);
        }
Ejemplo n.º 4
0
        private IssueCreate convertToViewModel(IssueCreateDTO dto, IssueCreate viewModel = null)
        {
            IssueCreate converted = viewModel ?? new IssueCreate();

            converted.Description = dto.Description;
            converted.ProjectID   = dto.ProjectID;
            converted.Title       = dto.Title;
            converted.IssueID     = dto.IssueID == 0 ? converted.IssueID : dto.IssueID;

            return(converted);
        }
Ejemplo n.º 5
0
        public static void Main()
        {
            // Settings needed to connect and use the Regular Service.
            string user     = ConfigurationManager.AppSettings["User"];
            string password = ConfigurationManager.AppSettings["Password"];
            string serviceEndpointAddress = ConfigurationManager.AppSettings["ServiceEndpointAddress"];

            // Creation of a channel connected to the Regular Service.
            var endpoint = new EndpointAddress(serviceEndpointAddress);
            var binding  = new BasicHttpBinding();
            ChannelFactory <IGitHubSoapService> channelFactory = new ChannelFactory <IGitHubSoapService>(binding, endpoint);

            channelFactory.Endpoint.Behaviors.Add(new AuthenticationHeaderBehavior());
            var serviceChannel = channelFactory.CreateChannel();

            // Create a new repository.
            var newRepo = new RepoCreate
            {
                name          = "Test-Repository",
                description   = "Just a test repository",
                has_downloads = true,
                has_issues    = true,
                has_wiki      = false,
                @private      = false
            };

            var createdRepo = serviceChannel.CreateRepo(user, password, newRepo);

            // Get the created repository.
            var repo = serviceChannel.GetRepo(user, "Test-Repository");

            // Edit the repository.
            var editRepo = new RepoEdit {
                has_downloads = false, name = "Test-Repository"
            };

            serviceChannel.EditRepo(user, password, "Test-Repository", editRepo);

            // Create an issue in the created repository.
            var newIssue = new IssueCreate {
                title = "Found a bug", body = "I'm having a problem with this.", assignee = "luismdcp"
            };
            var createdIssue = serviceChannel.CreateIssue(user, password, "Test-Repository", newIssue);

            // Edit the created issue.
            var editIssue = new IssueEdit {
                milestone = 1
            };

            serviceChannel.EditIssue(user, password, "Test-Repository", createdIssue.id, editIssue);
        }
Ejemplo n.º 6
0
        public ActionResult Create(IssueCreateDTO dto)
        {
            if (ModelState.IsValid)
            {
                string userID = User.Identity.GetUserId();
                Issue  issue  = null;
                if (!this.db.HasProjectAccess(dto.ProjectID, userID))
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                }

                if (dto.IssueID > 0)
                {
                    issue = this.db.Issues.Find(dto.IssueID);
                    if (issue == null ||
                        !this.db.HasProjectAccess(issue.ProjectID, userID) ||
                        (issue.ReporterID != userID && !this.db.HasProjectRole(issue.ProjectID, userID, Role.Manager))
                        )
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                    }
                }
                else
                {
                    issue             = new Issue();
                    issue.RaportDate  = DateTime.UtcNow;
                    issue.ReporterID  = userID;
                    issue.Status      = IssueStatus.Reported;
                    issue.IssueNumber = this.db.Issues.Where(i => i.ProjectID == dto.ProjectID).Count() + 1;
                }

                issue.ProjectID    = dto.ProjectID;
                issue.Description  = dto.Description;
                issue.LastModified = DateTime.UtcNow;
                issue.Title        = dto.Title;

                if (dto.IssueID == 0)
                {
                    db.Issues.Add(issue);
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                IssueCreate viewModel = this.getCreateModel();
                viewModel = this.convertToViewModel(dto, viewModel);
                return(View(viewModel));
            }
        }
        public Issue Create(string user, string password, string repo, IssueCreate createIssue)
        {
            var client  = new HttpClient();
            var uri     = String.Format("https://api.github.com/repos/{0}/{1}/issues", user, repo);
            var request = new HttpRequestMessage <IssueCreate>(createIssue,
                                                               new HttpMethod("POST"),
                                                               new Uri(uri),
                                                               new List <MediaTypeFormatter> {
                new JsonMediaTypeFormatter()
            });

            request.Content.Headers.ContentType        = new MediaTypeHeaderValue("application/json");
            client.DefaultRequestHeaders.Authorization = CreateBasicAuthentication(user, password);
            var response = client.SendAsync(request).Result;
            var result   = response.Content.ReadAsAsync <Issue>().Result;

            return(result);
        }
Ejemplo n.º 8
0
 public Issue Create(string user, string password, string repo, IssueCreate createIssue)
 {
     return(this.issuesRepository.Create(user, password, repo, createIssue));
 }
Ejemplo n.º 9
0
        public override async Task <bool> ReportPackageSourceAudit()
        {
            if (!this.AuditOptions.ContainsKey("GitLabReportUrl") || !this.AuditOptions.ContainsKey("GitLabReportName") || !this.AuditOptions.ContainsKey("GitLabToken"))
            {
                throw new ArgumentException("A required audit option for the GitLab environment is missing.");
            }
            HostUrl     = (string)this.AuditOptions["GitLabReportUrl"];
            Token       = (string)this.AuditOptions["GitLabToken"];
            ProjectName = (string)this.AuditOptions["GitLabReportName"];
            GitLabClient client = null;

            try
            {
                this.AuditEnvironment.Info("Connecting to project {0} at {1}", ProjectName, HostUrl);
                client = new GitLabClient(HostUrl, Token);
                IEnumerable <Project> projects = await client.Projects.Owned();

                Project = projects.Where(p => p.Name == ProjectName).FirstOrDefault();
                this.AuditEnvironment.Info("Connected to project {0}.", Project.PathWithNamespace);
            }
            catch (AggregateException ae)
            {
                AuditEnvironment.Error(ae, "Could not get project {0} at url {1}.", ProjectName, HostUrl);
                return(false);
            }
            catch (Exception e)
            {
                AuditEnvironment.Error(e, "Could not get project {0} at url {1}.", ProjectName, HostUrl);
                return(false);
            }
            if (Project == null)
            {
                AuditEnvironment.Error("Could not find the project {0}.", Project.Name);
                return(false);
            }
            if (!Project.IssuesEnabled)
            {
                AuditEnvironment.Error("Issues are not enabled for the project {0}/{1}.", Project.Owner, Project.Name);
                return(false);
            }
            if (AuditOptions.ContainsKey("GitLabReportTitle"))
            {
                IssueTitle = (string)AuditOptions["GitLabReportTitle"];
            }
            else
            {
                IssueTitle = string.Format("[DevAudit] {2} audit on {0} {1}", DateTime.UtcNow.ToShortDateString(), DateTime.UtcNow.ToShortTimeString(), Source.PackageManagerLabel);
            }
            BuildPackageSourceAuditReport();
            try
            {
                IssueCreate ic = new IssueCreate
                {
                    ProjectId   = Project.Id,
                    Title       = IssueTitle,
                    Description = IssueText.ToString()
                };
                Issue issue = await client.Issues.CreateAsync(ic);

                if (issue != null)
                {
                    AuditEnvironment.Success("Created issue #{0} '{1}' in GitLab project {2}/{3} at host url {4}.", issue.IssueId, issue.Title, Project.Owner, ProjectName, HostUrl);
                    return(true);
                }
                else
                {
                    AuditEnvironment.Error("Error creating new issue for project {0} at host url {1}. The issue object is null.", ProjectName, HostUrl);
                    return(false);
                }
            }
            catch (AggregateException ae)
            {
                AuditEnvironment.Error(ae, "Error creating new issue for project {0} at host url {1}.", ProjectName, HostUrl);
                return(false);
            }
            catch (Exception e)
            {
                AuditEnvironment.Error(e, "Error creating new issue for project {0} at host url {1}.", ProjectName, HostUrl);
                return(false);
            }
        }
Ejemplo n.º 10
0
        public Issue CreateIssue(string user, string password, string repo, IssueCreate createIssue)
        {
            IIssuesService issuesService = ObjectFactory.GetInstance <IIssuesService>();

            return(issuesService.Create(user, password, repo, createIssue));
        }
Ejemplo n.º 11
0
 public Issue Create(IssueCreate issueCreate)
 {
     return(_api.Post().With(issueCreate).To <Issue>(string.Format(ProjectIssuesUrl, issueCreate.Id)));
 }