diff --git a/src/Atlassian.Stash/Api/PullRequests.cs b/src/Atlassian.Stash/Api/PullRequests.cs index 8a31670..876d259 100644 --- a/src/Atlassian.Stash/Api/PullRequests.cs +++ b/src/Atlassian.Stash/Api/PullRequests.cs @@ -1,4 +1,4 @@ -using System; +using System; using Atlassian.Stash.Entities; using Atlassian.Stash.Helpers; using Atlassian.Stash.Workers; @@ -25,6 +25,9 @@ public enum Direction } private const string PULL_REQUEST = "rest/api/1.0/projects/{0}/repos/{1}/pull-requests"; + private const string PULL_REQUEST_GET = "rest/api/1.0/projects/{0}/repos/{1}/pull-requests/{2}"; + private const string PULL_REQUEST_ACTIVITIES = "rest/api/1.0/projects/{0}/repos/{1}/pull-requests/{2}/activities"; + private const string PULL_REQUEST_COMMITS = "rest/api/1.0/projects/{0}/repos/{1}/pull-requests/{2}/commits"; private const string PULL_REQUEST_UPDATE = "rest/api/1.0/projects/{0}/repos/{1}/pull-requests/{2}"; private const string PULL_REQUEST_MERGEABLE = "rest/api/1.0/projects/{0}/repos/{1}/pull-requests/{2}/merge"; private const string PULL_REQUEST_MERGE = "rest/api/1.0/projects/{0}/repos/{1}/pull-requests/{2}/merge?version={3}"; @@ -146,6 +149,52 @@ public async Task Merge(PullRequest pullRequest, string projectKey) } } + /// + /// Get an existing pull request. + /// + /// + /// + /// + /// The pull request + public async Task Get(string pullRequestId, string projectKey, string slug) + { + string requestUrl = UrlBuilder.FormatRestApiUrl(PULL_REQUEST_GET, null, projectKey, slug, pullRequestId); + + PullRequest pullRequest = await _httpWorker.GetAsync(requestUrl).ConfigureAwait(false); + + return pullRequest; + } + + /// + /// Get pull request activities. + /// + /// + /// + /// + /// + /// The pull request activities. + public async Task> GetActivities(string pullRequestId, string projectKey, string slug, RequestOptions requestOptions = null) + { + var requestUrl = UrlBuilder.FormatRestApiUrl(PULL_REQUEST_ACTIVITIES, requestOptions, projectKey, slug, pullRequestId); + + return await _httpWorker.GetAsync>(requestUrl).ConfigureAwait(false); + } + + /// + /// Get pull request commits. + /// + /// + /// + /// + /// + /// The commits. + public async Task> GetCommits(string pullRequestId, string projectKey, string slug, RequestOptions requestOptions = null) + { + var requestUrl = UrlBuilder.FormatRestApiUrl(PULL_REQUEST_COMMITS, requestOptions, projectKey, slug, pullRequestId); + + return await _httpWorker.GetAsync>(requestUrl).ConfigureAwait(false); + } + /// /// Retrieve a page of pull requests to or from the specified repository. /// diff --git a/src/Atlassian.Stash/Entities/AuthorWrapper.cs b/src/Atlassian.Stash/Entities/AuthorWrapper.cs index 590dfc0..f5709fc 100644 --- a/src/Atlassian.Stash/Entities/AuthorWrapper.cs +++ b/src/Atlassian.Stash/Entities/AuthorWrapper.cs @@ -12,5 +12,7 @@ public class AuthorWrapper public Author User { get; set; } [JsonProperty("status")] public string Status { get; set; } + [JsonProperty("lastReviewedCommit")] + public string LastReviewedCommit { get; set; } } } diff --git a/src/Atlassian.Stash/Entities/Comment.cs b/src/Atlassian.Stash/Entities/Comment.cs new file mode 100644 index 0000000..e8a6d70 --- /dev/null +++ b/src/Atlassian.Stash/Entities/Comment.cs @@ -0,0 +1,61 @@ +using Atlassian.Stash.Converters; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using System; + +namespace Atlassian.Stash.Entities +{ + public enum TaskSeverity + { + NONE, + NORMAL, + BLOCKER, + } + + public enum TaskState + { + NONE, + OPEN, + RESOLVED, + } + + public class Comment + { + public CommentProperties Properties { get; set; } + + public string Id { get; set; } + + public string Version { get; set; } + + public string Type { get; set; } + + public string Text { get; set; } + + public Author Author { get; set; } + + [JsonConverter(typeof(TimestampConverter))] + public DateTime CreatedDate { get; set; } + + [JsonConverter(typeof(TimestampConverter))] + public DateTime UpdatedDate { get; set; } + + public Comment[] Comments { get; set; } + + public Comment[] Tasks { get; set; } + + public PermittedOperations PermittedOperations { get; set; } + + [JsonConverter(typeof(TimestampConverter))] + public DateTime ResolvedDate { get; set; } + + public Author Resolver { get; set; } + + [JsonConverter(typeof(StringEnumConverter))] + public TaskSeverity Severity { get; set; } + + [JsonConverter(typeof(StringEnumConverter))] + public TaskState State { get; set; } + + public Comment Anchor { get; set; } + } +} diff --git a/src/Atlassian.Stash/Entities/CommentAnchor.cs b/src/Atlassian.Stash/Entities/CommentAnchor.cs new file mode 100644 index 0000000..5765a4c --- /dev/null +++ b/src/Atlassian.Stash/Entities/CommentAnchor.cs @@ -0,0 +1,52 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Atlassian.Stash.Entities +{ + public enum DiffType + { + NONE, + COMMIT, + EFFECTIVE, + RANGE, + } + + public enum FileType + { + NONE, + FROM, + TO + } + + public enum LineType + { + NONE, + ADDED, + REMOVED, + CONTEXT + } + + public class CommentAnchor + { + public string FromHash { get; set; } + + public string ToHash { get; set; } + + public int Line { get; set; } + + [JsonConverter(typeof(StringEnumConverter))] + public LineType LineType { get; set; } + + [JsonConverter(typeof(StringEnumConverter))] + public FileType FileType { get; set; } + + public string Path { get; set; } + + public string Srcpath { get; set; } + + [JsonConverter(typeof(StringEnumConverter))] + public DiffType DiffType { get; set; } + + public bool Orphaned { get; set; } + } +} diff --git a/src/Atlassian.Stash/Entities/CommentProperties.cs b/src/Atlassian.Stash/Entities/CommentProperties.cs new file mode 100644 index 0000000..e38e93a --- /dev/null +++ b/src/Atlassian.Stash/Entities/CommentProperties.cs @@ -0,0 +1,19 @@ +namespace Atlassian.Stash.Entities +{ + public class CommentProperties + { + public string RepositoryId { get; set; } + + public string SuggestionState { get; set; } + + public LikedBy LikedBy { get; set; } + + public Reactions[] Reactions { get; set; } + + public string[] Issues { get; set; } + + public string DiffAnchorPath { get; set; } + + public string SuggestionIndex { get; set; } + } +} diff --git a/src/Atlassian.Stash/Entities/Commit.cs b/src/Atlassian.Stash/Entities/Commit.cs index 44fefbc..cd6c52e 100644 --- a/src/Atlassian.Stash/Entities/Commit.cs +++ b/src/Atlassian.Stash/Entities/Commit.cs @@ -1,5 +1,6 @@ -using Atlassian.Stash.Converters; +using Atlassian.Stash.Converters; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; using System; namespace Atlassian.Stash.Entities @@ -7,11 +8,23 @@ namespace Atlassian.Stash.Entities public class Commit { public string Id { get; set; } + public string DisplayId { get; set; } + public Author Author { get; set; } + [JsonConverter(typeof(TimestampConverter))] public DateTime AuthorTimestamp { get; set; } + public string Message { get; set; } - public Parent[] Parents { get; set; } + + public Commit[] Parents { get; set; } + + public Author Committer { get; set; } + + [JsonConverter(typeof(TimestampConverter))] + public DateTime CommitterTimestamp { get; set; } + + public CommitProperties Properties { get; set; } } } diff --git a/src/Atlassian.Stash/Entities/CommitProperties.cs b/src/Atlassian.Stash/Entities/CommitProperties.cs new file mode 100644 index 0000000..765f3de --- /dev/null +++ b/src/Atlassian.Stash/Entities/CommitProperties.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace Atlassian.Stash.Entities +{ + public class CommitProperties + { + [JsonProperty("jira-key")] + public string[] JiraKey { get; set; } + + public int CommentCount { get; set; } + } +} diff --git a/src/Atlassian.Stash/Entities/CommitUpdate.cs b/src/Atlassian.Stash/Entities/CommitUpdate.cs new file mode 100644 index 0000000..69392af --- /dev/null +++ b/src/Atlassian.Stash/Entities/CommitUpdate.cs @@ -0,0 +1,9 @@ +namespace Atlassian.Stash.Entities +{ + public class CommitUpdate + { + public int Total { get; set; } + + public Commit[] Commits { get; set; } + } +} diff --git a/src/Atlassian.Stash/Entities/Diff.cs b/src/Atlassian.Stash/Entities/Diff.cs new file mode 100644 index 0000000..c3967f6 --- /dev/null +++ b/src/Atlassian.Stash/Entities/Diff.cs @@ -0,0 +1,15 @@ +namespace Atlassian.Stash.Entities +{ + public class Diff + { + public Path Source { get; set; } + + public Path Destination { get; set; } + + public Hunk[] Hunks { get; set; } + + public DiffProperties Properties { get; set; } + + public bool Truncated { get; set; } + } +} diff --git a/src/Atlassian.Stash/Entities/DiffProperties.cs b/src/Atlassian.Stash/Entities/DiffProperties.cs new file mode 100644 index 0000000..5ec7c26 --- /dev/null +++ b/src/Atlassian.Stash/Entities/DiffProperties.cs @@ -0,0 +1,11 @@ +namespace Atlassian.Stash.Entities +{ + public class DiffProperties + { + public string ToHash { get; set; } + + public bool Current { get; set; } + + public string FromHash { get; set; } + } +} diff --git a/src/Atlassian.Stash/Entities/Emoticon.cs b/src/Atlassian.Stash/Entities/Emoticon.cs new file mode 100644 index 0000000..389c607 --- /dev/null +++ b/src/Atlassian.Stash/Entities/Emoticon.cs @@ -0,0 +1,9 @@ +namespace Atlassian.Stash.Entities +{ + public class Emoticon + { + public string Shortcut { get; set; } + + public string Url { get; set; } + } +} diff --git a/src/Atlassian.Stash/Entities/Hunk.cs b/src/Atlassian.Stash/Entities/Hunk.cs new file mode 100644 index 0000000..493c051 --- /dev/null +++ b/src/Atlassian.Stash/Entities/Hunk.cs @@ -0,0 +1,19 @@ +namespace Atlassian.Stash.Entities +{ + public class Hunk + { + public string Context { get; set; } + + public int SourceLine { get; set; } + + public int SourceSpan { get; set; } + + public int DestinationLine { get; set; } + + public int DestinationSpan { get; set; } + + public Segment[] Segments { get; set; } + + public bool Truncated { get; set; } + } +} diff --git a/src/Atlassian.Stash/Entities/LikedBy.cs b/src/Atlassian.Stash/Entities/LikedBy.cs new file mode 100644 index 0000000..7463295 --- /dev/null +++ b/src/Atlassian.Stash/Entities/LikedBy.cs @@ -0,0 +1,9 @@ +namespace Atlassian.Stash.Entities +{ + public class LikedBy + { + public int Total { get; set; } + + public Author[] Likers { get; set; } + } +} diff --git a/src/Atlassian.Stash/Entities/PermittedOperations.cs b/src/Atlassian.Stash/Entities/PermittedOperations.cs new file mode 100644 index 0000000..0ace938 --- /dev/null +++ b/src/Atlassian.Stash/Entities/PermittedOperations.cs @@ -0,0 +1,11 @@ +namespace Atlassian.Stash.Entities +{ + public class PermittedOperations + { + public bool Editable { get; set; } + + public bool Transitionable { get; set; } + + public bool Deletable { get; set; } + } +} diff --git a/src/Atlassian.Stash/Entities/PullRequest.cs b/src/Atlassian.Stash/Entities/PullRequest.cs index 11424d7..d94a3e5 100644 --- a/src/Atlassian.Stash/Entities/PullRequest.cs +++ b/src/Atlassian.Stash/Entities/PullRequest.cs @@ -1,10 +1,11 @@ -using Newtonsoft.Json; +using System; +using Atlassian.Stash.Converters; +using Newtonsoft.Json; using Newtonsoft.Json.Converters; using System.Collections.Generic; namespace Atlassian.Stash.Entities { - public enum PullRequestState { OPEN, @@ -16,36 +17,43 @@ public enum PullRequestState public class PullRequest { public string Id { get; set; } - [JsonProperty("version")] + public string Version { get; set; } - [JsonProperty("title")] public string Title { get; set; } - [JsonProperty("description")] + public string Description { get; set; } - [JsonProperty("state")] + [JsonConverter(typeof(StringEnumConverter))] public PullRequestState State { get; set; } - [JsonProperty("open")] + public bool Open { get; set; } - [JsonProperty("closed")] + public bool Closed { get; set; } - public string CreatedDate { get; set; } - public string UpdatedDate { get; set; } - [JsonProperty("fromRef")] + + [JsonConverter(typeof(TimestampConverter))] + public DateTime CreatedDate { get; set; } + + [JsonConverter(typeof(TimestampConverter))] + public DateTime UpdatedDate { get; set; } + + [JsonConverter(typeof(TimestampConverter))] + public DateTime ClosedDate { get; set; } + public Ref FromRef { get; set; } - [JsonProperty("toRef")] + public Ref ToRef { get; set; } - [JsonProperty("locked")] public bool Locked { get; set; } public AuthorWrapper Author { get; set; } - [JsonProperty("reviewers")] + public AuthorWrapper[] Reviewers { get; set; } + public List Participants { get; set; } public Link Link { get; set; } + public Links Links { get; set; } } } diff --git a/src/Atlassian.Stash/Entities/PullRequestActivity.cs b/src/Atlassian.Stash/Entities/PullRequestActivity.cs new file mode 100644 index 0000000..d595516 --- /dev/null +++ b/src/Atlassian.Stash/Entities/PullRequestActivity.cs @@ -0,0 +1,69 @@ +using System; +using Atlassian.Stash.Converters; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Atlassian.Stash.Entities +{ + public enum PullRequestActivityType + { + NONE, + MERGED, + UNAPPROVED, + APPROVED, + COMMENTED, + RESCOPED, + REVIEWED, + OPENED, + REOPENED, + DECLINED, + UPDATED + } + + public enum CommentActionType + { + NONE, + ADDED, + REMOVED + } + + public class PullRequestActivity + { + public string Id { get; set; } + + [JsonConverter(typeof(TimestampConverter))] + public DateTime CreatedDate { get; set; } + + public User User { get; set; } + + public Commit Commit { get; set; } + + [JsonConverter(typeof(StringEnumConverter))] + public PullRequestActivityType Action { get; set; } + + [JsonConverter(typeof(StringEnumConverter))] + public CommentActionType CommentAction { get; set; } + + public Comment Comment { get; set; } + + public CommentAnchor CommentAnchor { get; set; } + + public Diff Diff { get; set; } + + public string PreviousFromHash { get; set; } + + public string FromHash { get; set; } + + public string PreviousToHash { get; set; } + + public string ToHash { get; set; } + + public CommitUpdate Added { get; set; } + + public CommitUpdate Removed { get; set; } + + public Author[] AddedReviewers { get; set; } + + public Author[] RemovedReviewers { get; set; } + } +} diff --git a/src/Atlassian.Stash/Entities/Reactions.cs b/src/Atlassian.Stash/Entities/Reactions.cs new file mode 100644 index 0000000..3b69e8e --- /dev/null +++ b/src/Atlassian.Stash/Entities/Reactions.cs @@ -0,0 +1,11 @@ +namespace Atlassian.Stash.Entities +{ + public class Reactions + { + public Emoticon Emoticon { get; set; } + + public User[] Users { get; set; } + + public string[] Issues { get; set; } + } +} diff --git a/src/Atlassian.Stash/Entities/Ref.cs b/src/Atlassian.Stash/Entities/Ref.cs index 8af0dd3..f266295 100644 --- a/src/Atlassian.Stash/Entities/Ref.cs +++ b/src/Atlassian.Stash/Entities/Ref.cs @@ -10,5 +10,7 @@ public class Ref public string LatestChangeset { get; set; } [JsonProperty("repository")] public Repository Repository { get; set; } + [JsonProperty("latestCommit")] + public string LatestCommit { get; set; } } } diff --git a/src/Atlassian.Stash/Entities/Repository.cs b/src/Atlassian.Stash/Entities/Repository.cs index 23a0d6a..ca9b63a 100644 --- a/src/Atlassian.Stash/Entities/Repository.cs +++ b/src/Atlassian.Stash/Entities/Repository.cs @@ -22,5 +22,7 @@ public class Repository public Links Links { get; set; } [JsonProperty("project")] public Project Project { get; set; } + [JsonProperty("hierarchyId")] + public string HierarchyId { get; set; } } } diff --git a/src/Atlassian.Stash/Entities/Segment.cs b/src/Atlassian.Stash/Entities/Segment.cs new file mode 100644 index 0000000..5d4e0c7 --- /dev/null +++ b/src/Atlassian.Stash/Entities/Segment.cs @@ -0,0 +1,23 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Atlassian.Stash.Entities +{ + public enum ContextType + { + NONE, + CONTEXT, + ADDED, + REMOVED + } + + public class Segment + { + [JsonConverter(typeof(StringEnumConverter))] + public ContextType Type { get; set; } + + public SegmentLine[] Lines { get; set; } + + public bool Truncated { get; set; } + } +} diff --git a/src/Atlassian.Stash/Entities/SegmentLine.cs b/src/Atlassian.Stash/Entities/SegmentLine.cs new file mode 100644 index 0000000..439299d --- /dev/null +++ b/src/Atlassian.Stash/Entities/SegmentLine.cs @@ -0,0 +1,15 @@ +namespace Atlassian.Stash.Entities +{ + public class SegmentLine + { + public int Destination { get; set; } + + public int Source { get; set; } + + public string Line { get; set; } + + public bool Truncated { get; set; } + + public int[] CommentIds { get; set; } + } +} diff --git a/src/Atlassian.Stash/Entities/User.cs b/src/Atlassian.Stash/Entities/User.cs index 364bc79..728820d 100644 --- a/src/Atlassian.Stash/Entities/User.cs +++ b/src/Atlassian.Stash/Entities/User.cs @@ -24,5 +24,11 @@ public class User [JsonProperty("lastAuthenticationTimestamp")] public long LastAuthenticationTimestamp { get; set; } + + [JsonProperty("displayName")] + public string DisplayName { get; set; } + + [JsonProperty("links")] + public Links Links { get; set; } } }