Ejemplo n.º 1
0
        private static void TestRepositoriesEndPoint(SharpBucketV1 sharpBucket)
        {
            var    repositoriesEndPoint = sharpBucket.RepositoriesEndPoint(accountName, repository);
            var    tags       = repositoriesEndPoint.ListTags();
            var    branches   = repositoriesEndPoint.ListBranches();
            var    mainBranch = repositoriesEndPoint.GetMainBranch();
            string WIKI_PAGE  = "";
            var    wiki       = repositoriesEndPoint.GetWiki(WIKI_PAGE);
            var    newPage    = new Wiki {
                data = "Hello to my new page"
            };
            var newWiki    = repositoriesEndPoint.PostWiki(newPage, "NewPage");
            var changeSet  = repositoriesEndPoint.ListChangeset();
            var change     = changeSet.changesets[4];
            var getChange  = repositoriesEndPoint.GetChangeset(change.node);
            var diffStats  = repositoriesEndPoint.GetChangesetDiffstat(change.node);
            var repoEvents = repositoriesEndPoint.ListEvents();
            var links      = repositoriesEndPoint.ListLinks();
            var newLink    = new SharpBucket.V1.Pocos.Link {
                id = 100
            };
            var newLinkResponse = repositoriesEndPoint.PostLink(newLink);
            var link            = repositoriesEndPoint.GetLink(newLinkResponse.id);

            newLinkResponse.handler.name = "sfsdf";
            var updatedLink = repositoriesEndPoint.PutLink(newLinkResponse);

            repositoriesEndPoint.DeleteLink(updatedLink);
        }
 public void Init()
 {
     sharpBucket          = TestHelpers.GetV1ClientAuthenticatedWithOAuth();
     accountName          = "mirror";
     repositoriesEndPoint = sharpBucket.RepositoriesEndPoint(accountName, REPOSITORY_NAME);
 }
Ejemplo n.º 3
0
        private static void TestIssuesEndPoint(SharpBucketV1 sharpBucket)
        {
            var issuesResource = sharpBucket.RepositoriesEndPoint(accountName, repository).IssuesResource();

            int ISSUE_ID = 5;
            // Issues
            var issues   = issuesResource.ListIssues();
            var newIssue = new Issue {
                title = "Let's add a new issue", content = "Some issue content", status = "new", priority = "trivial", kind = "bug"
            };
            var newIssueResult = issuesResource.PostIssue(newIssue);
            var issue          = issuesResource.GetIssue(newIssueResult.local_id);
            var changedIssue   = new Issue {
                title = "Completely new title", content = "Hi!", status = "new", local_id = issue.local_id
            };
            var changedIssueResult = issuesResource.PutIssue(changedIssue);

            issuesResource.DeleteIssue(changedIssueResult.local_id);

            // Issue comments
            var issueResource = issuesResource.IssueResource(ISSUE_ID);
            var issueComments = issueResource.ListComments();
            var newComment    = new Comment {
                content = "This bug is really annoying!"
            };
            var newCommentResult = issueResource.PostComment(newComment);
            var comment          = issueResource.GetIssueComment(newCommentResult.comment_id);

            comment.content = "The bug is still annoying";
            var updatedCommentRes = issueResource.PutIssueComment(comment);

            issueResource.DeleteIssueComment(updatedCommentRes.comment_id);

            // Issue followers
            var issueFollowers = issueResource.ListFollowers();

            // Components
            var components   = issuesResource.ListComponents();
            var newComponent = new Component {
                name = "Awesome component"
            };
            var newComponentRes = issuesResource.PostComponent(newComponent);
            var component       = issuesResource.GetComponent(newComponentRes.id);

            component.name = "Even more awesome component";
            var updatedComponent = issuesResource.PutComponent(component);

            issuesResource.DeleteComponent(updatedComponent.id);

            // Milestones
            var milestones   = issuesResource.ListMilestones();
            var newMilestone = new Milestone {
                name = "Awesome milestone"
            };
            var newMilestoneRes = issuesResource.PostMilestone(newMilestone);
            var milestone       = issuesResource.GetMilestone(newMilestoneRes.id);

            milestone.name = "Even more awesome milestone";
            var updatedMilestone = issuesResource.PutMilestone(milestone);

            issuesResource.DeleteMilestone(updatedMilestone.id);

            // Versions
            var versions   = issuesResource.ListVersions();
            var newVersion = new Version {
                name = "Awesome version"
            };
            var newVersionRes = issuesResource.PostVersion(newVersion);
            var version       = issuesResource.GetVersion(newVersionRes.id);

            version.name = "Even more awesome version";
            var updatedversion = issuesResource.PutVersion(version);

            issuesResource.DeleteVersion(updatedversion.id);
        }
Ejemplo n.º 4
0
        public override Task <bool> ReportPackageSourceAudit()
        {
            if (!AuditOptions.ContainsKey("BitBucketReportAccount") || !AuditOptions.ContainsKey("BitBucketReportName") || !AuditOptions.ContainsKey("BitBucketKey"))
            {
                throw new ArgumentException("The BitBucketReportAccount, BitBucketReportName, and BitBucketReportKey audit options must be present.");
            }
            string key = (string)AuditOptions["BitBucketKey"];

            string[] k = key.Split('|');
            if (k.Count() != 2)
            {
                throw new ArgumentException("The BitBucketReportKey audit option must have the format consumer_key|secret.");
            }
            string consumer = k[0], secret = k[1];
            string account    = (string)AuditOptions["BitBucketReportAccount"];
            string repository = (string)AuditOptions["BitBucketReportName"];

            if (AuditOptions.ContainsKey("BitBucketReportTitle"))
            {
                IssueTitle = (string)AuditOptions["BitBucketReportTitle"];
            }
            else
            {
                IssueTitle = string.Format("[DevAudit] {0} audit on {1} {2}", Source.PackageManagerLabel, DateTime.UtcNow.ToShortDateString(), DateTime.UtcNow.ToShortTimeString());
            }
            SharpBucketV1 sharp_bucket = new SharpBucketV1();

            sharp_bucket.OAuth2LeggedAuthentication(consumer, secret);
            RepositoriesEndPoint repository_endpoint = sharp_bucket.RepositoriesEndPoint(account, repository);
            IssuesResource       r;

            try
            {
                r = repository_endpoint.IssuesResource();
            }
            catch (Exception e)
            {
                AuditEnvironment.Error(e, "Could not get issues resource for repository {0}/{1}.", account, repository);
                return(Task.FromResult(false));
            }
            BuildPackageSourceAuditReport();
            Issue issue = new Issue()
            {
                title    = IssueTitle,
                content  = IssueText.ToString(),
                status   = "new",
                priority = "major",
                kind     = "bug"
            };

            try
            {
                Issue i = r.PostIssue(issue);
                if (i == null)
                {
                    AuditEnvironment.Error("Could not post issue to repository {0}/{1}.", account, repository);
                    return(Task.FromResult(false));
                }
                else
                {
                    AuditEnvironment.Success("Created issue {0} at {1}.", i.title, i.resource_uri);
                }
            }
            catch (Exception e)
            {
                AuditEnvironment.Error(e, "Could not post issue to repository {0}/{1}.", account, repository);
                return(Task.FromResult(false));
            }

            return(Task.FromResult(true));
        }