// Formerly known as Stash
        public BitBucketPullRequestProvider(ProgramArgs programArgs)
        {
            _programArgs = programArgs;
            DiscoverBitBucketServerCredentials();
#pragma warning disable 618
            _bitBucketClient.OAuth2LeggedAuthentication(_programArgs.BitBucketApiKey, _programArgs.BitBucketApiSecret);
#pragma warning restore 618
        }
Пример #2
0
        public static SharpBucketV2 GetV2ClientAuthenticatedWithOAuth()
        {
            var consumerKey       = Environment.GetEnvironmentVariable(SbConsumerKey);
            var consumerSecretKey = Environment.GetEnvironmentVariable(SbConsumerSecretKey);
            var sharpbucket       = new SharpBucketV2();

            sharpbucket.OAuth2LeggedAuthentication(consumerKey, consumerSecretKey);
            return(sharpbucket);
        }
Пример #3
0
        public BitbucketAPIService(string username, string publicKey, string secretKey)
        {
            Username   = username;
            PublicKey  = publicKey;
            PrivateKey = secretKey;

            m_sharpBucket2 = new SharpBucketV2();
            m_sharpBucket2.OAuth2LeggedAuthentication(PublicKey, PrivateKey);
        }
Пример #4
0
        private static void TestApiV2()
        {
            var sharpBucket = new SharpBucketV2();

            ReadTestDataOauth();
            sharpBucket.OAuth2LeggedAuthentication(consumerKey, consumerSecretKey);
            //TestUsersEndPoint(sharpBucket);
            //TestTeamsEndPoint(sharpBucket);
            TestRestRepositoriesEndPoint(sharpBucket);
        }
 // Formerly known as Stash
 public BitBucketPullRequestProvider(ProgramArgs programArgs)
 {
     _programArgs = programArgs;
     DiscoverBitBucketServerCredentials();
     _bitBucketClient.OAuth2LeggedAuthentication(_programArgs.BitBucketApiKey, _programArgs.BitBucketApiSecret);
 }
Пример #6
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());
            }
            SharpBucketV2 sharp_bucket = new SharpBucketV2();

            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));
        }