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 RepositoriesEndPoint(string accountName, string repository, SharpBucketV1 sharpBucketV1) { _sharpBucketV1 = sharpBucketV1; _baserUrl = "repositories/" + accountName + "/" + repository + "/"; _issuesUrl = _baserUrl + "issues/"; _issuesIdUrl = _issuesUrl + "{0}/"; }
/// <summary> /// Constructor for a user /// </summary> /// <param name="username">the username of the current user</param> /// <param name="password">the password of the current user</param> public User(string username, string password) { logged = false; this.username = username; this.password = password; //Sharp bucket has two versions of API so we authenticate with both as well as our own RESTSHARP client v1Api = new SharpBucketV1(); v1Api.BasicAuthentication(username, password); try { this.accountName = v1Api.UserEndPoint().GetInfo().user.username; logged = true; } catch (Exception e) { Console.WriteLine(e.Message); return; } v2Api = new SharpBucketV2(); v2Api.BasicAuthentication(username, password); client = new RestClient("https://api.bitbucket.org/"); client.Authenticator = new HttpBasicAuthenticator(username, password); }
private static void TestApiV1() { var sharpBucket = new SharpBucketV1(); // Decide on which authentication you wish to use //ReadTestDataBasic(); //sharpBucket.BasicAuthentication(email, password); ReadTestDataOauth(); // Two legged OAuth, just supply the consumerKey and the consumerSecretKey and you are done sharpBucket.OAuth2LeggedAuthentication(consumerKey, consumerSecretKey); // Three legged OAuth. We can supply our own callback url to which bitbucket will send our pin // If we use "oob" as the callback url we will get the bitbuckets url address which will have our pin //var authenticator = sharpBucket.OAuth3LeggedAuthentication(consumerKey, consumerSecretKey, "oob"); //var uri = authenticator.StartAuthentication(); //Process.Start(uri); //var pin = Console.ReadLine(); // we can now do the final step by using the pin to get our access tokens //authenticator.AuthenticateWithPin(pin); // of if you saved the tokens you can simply use those // var authenticator = sharpBucket.OAuth3LeggedAuthentication(consumerKey, consumerSecretKey, "oauthtoken", "oauthtokensecret"); TestUserEndPoint(sharpBucket); TestIssuesEndPoint(sharpBucket); TestRepositoriesEndPoint(sharpBucket); TestUsersEndPoint(sharpBucket); TestPrivilegesEndPoint(sharpBucket); }
private static void TestUserEndPoint(SharpBucketV1 sharpBucket) { var userEndPoint = sharpBucket.UserEndPoint(); var info = userEndPoint.GetInfo(); var privileges = userEndPoint.ListPrivileges(); var follows = userEndPoint.ListFollows(); var userRepos = userEndPoint.ListRepositories(); var userReposOverview = userEndPoint.RepositoriesOverview(); var userRepositoryDashboard = userEndPoint.GetRepositoryDasboard(); }
public static SharpBucketV1 GetV1ClientAuthenticatedWithOAuth() { //get the environment variable from OS registry key for the current user var consumerKey = Environment.GetEnvironmentVariable(SbConsumerKey); var consumerSecretKey = Environment.GetEnvironmentVariable(SbConsumerSecretKey); var sharpbucket = new SharpBucketV1(); sharpbucket.OAuth2LeggedAuthentication(consumerKey, consumerSecretKey); return(sharpbucket); }
private static void TestUsersEndPoint(SharpBucketV1 sharpBucket) { var usersEndPoint = sharpBucket.UsersEndPoint(accountName); //var userEvents = usersEP.ListUserEvents(); //var userPrivileges = usersEP.ListUserPrivileges(); var invitations = usersEndPoint.ListInvitations(); var email = "*****@*****.**"; var invitationsForEmail = usersEndPoint.GetInvitationsFor(email); var followers = usersEndPoint.ListFollowers(); var consumers = usersEndPoint.ListConsumers(); int?CONSUMER_ID = consumers[0].id; var consumer = usersEndPoint.GetConsumer(CONSUMER_ID); var ssh_keys = usersEndPoint.ListSSHKeys(); int?PK = ssh_keys[0].pk; var getSSH = usersEndPoint.GetSSHKey(PK); }
public GroupsEndPoint(string accountName, SharpBucketV1 sharpBucketV1) { _sharpBucketV1 = sharpBucketV1; _baseUrl = $"groups/{accountName}/"; }
public PrivilegesEndPoint(string accountName, SharpBucketV1 sharpBucketV1) { _sharpBucketV1 = sharpBucketV1; _baseUrl = "privileges/" + accountName + "/"; }
public UsersEndPoint(string accountName, SharpBucketV1 sharpBucketV1) { _sharpBucketV1 = sharpBucketV1; _baseUrl = "users/" + accountName + "/"; }
private static void TestPrivilegesEndPoint(SharpBucketV1 sharpBucket) { var privilegesEndPoint = sharpBucket.PrivilegesEndPoint(accountName); var privileges = privilegesEndPoint.ListRepositoryPrivileges(repository); var privilege = privilegesEndPoint.GetPrivilegesForAccount(repository, accountName); }
public void Init() { sharpBucket = TestHelpers.GetV1ClientAuthenticatedWithOAuth(); accountName = TestHelpers.GetAccountName(); groupsEndPoint = sharpBucket.GroupsEndPoint(accountName); }
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); }
public UserEndPoint(SharpBucketV1 sharpBucketV1) { _sharpBucketV1 = sharpBucketV1; _baseUrl = "user/"; }
public void Init() { sharpBucket = TestHelpers.GetV1ClientAuthenticatedWithOAuth(); accountName = "mirror"; repositoriesEndPoint = sharpBucket.RepositoriesEndPoint(accountName, REPOSITORY_NAME); }
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)); }