git_wand 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ae6e8fdec1bd3b979918df924777d38db193fe7
4
- data.tar.gz: e34eed064cb30626bc35487a8968671d5b1ed785
3
+ metadata.gz: 1352dfdc26e4ba8679a4a8cb2d78f6988289c31b
4
+ data.tar.gz: 87e758e81390c6d6826a78068f77b07e1f6008d8
5
5
  SHA512:
6
- metadata.gz: e7f1b0a56f607a8dec03346bc3c620dc684aba491ef590b3ee835b269a945d545a8081259d232024a89cbe8d0eeedc7bbf1ae4d6b5e58cee15881c096b2c081d
7
- data.tar.gz: 3163dea06795cff5229a674121d6592b10a71563728331909eb857f0d6376456979c5b2d54fc5fc339b2205fa850b5dc4de4f7314e524c4bbe56a2443dcb1659
6
+ metadata.gz: 36bc24310b68944a312f3bbff7669d9c76d2ee874b893aed8e06dd5ab273e731a4da1e8ccb57fd105bc3c7e94b764af99e3033460485ba0c1d4f35de2c34759c
7
+ data.tar.gz: a5e2b48498d74380bd936d65c3d3d85a07f87385b4f718fb6303e5198973d4c4a642af7d2f211dab4319cd4062b5fa72d2cae159c30b9e5a673a21232ceddbc9
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /bin/test
data/lib/git_wand.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "git_wand/version"
2
+ require "git_wand/github/resource"
2
3
  require "git_wand/github/api/client"
3
4
 
4
5
  module GitWand
@@ -1,5 +1,10 @@
1
1
  require_relative "request"
2
2
  require_relative "result"
3
+ require_relative "commands/repository"
4
+ require_relative "commands/issue"
5
+ require_relative "commands/pull_request"
6
+ require_relative "commands/branch"
7
+ require_relative "commands/file"
3
8
 
4
9
  module GitWand
5
10
  module GitHub
@@ -8,6 +13,12 @@ module GitWand
8
13
  extend self
9
14
 
10
15
  class Client
16
+ include Commands::Repository
17
+ include Commands::Issue
18
+ include Commands::PullRequest
19
+ include Commands::Branch
20
+ include Commands::File
21
+
11
22
  attr_reader :username, :token
12
23
 
13
24
  def initialize(username:, token:)
@@ -23,36 +34,20 @@ module GitWand
23
34
  result
24
35
  end
25
36
 
26
- def create_repository(name:, private: false)
27
- parameters = {
28
- name: name,
29
- private: private
30
- }
31
- response = post(resource: "user/repos", parameters: parameters)
32
- result = Result.new
33
- result.success = response[:status][:code] == "201"
34
- result.body = response[:body]
35
- result
36
- end
37
-
38
- def delete_repository(name:)
39
- response = delete(resource: "repos/#{username}/#{name}")
40
- result = Result.new
41
- result.success = response[:status][:code] == "204"
42
- result.body = response[:body]
43
- result
44
- end
45
-
46
37
  private
47
38
 
48
- def get(resource:)
49
- Request::http_request(method: :get, resource: resource, client: self)
39
+ def get(resource:, query_parameters: nil)
40
+ Request::http_request(method: :get, resource: resource, client: self, query_parameters: query_parameters)
50
41
  end
51
42
 
52
43
  def post(resource:, parameters: {})
53
44
  Request::http_request(method: :post, resource: resource, client: self, parameters: parameters)
54
45
  end
55
46
 
47
+ def put(resource:, parameters: {})
48
+ Request::http_request(method: :put, resource: resource, client: self, parameters: parameters)
49
+ end
50
+
56
51
  def delete(resource:)
57
52
  Request::http_request(method: :delete, resource: resource, client: self)
58
53
  end
@@ -0,0 +1,52 @@
1
+ module GitWand
2
+ module GitHub
3
+ module API
4
+
5
+ module Commands
6
+ module Branch
7
+
8
+ # Get Branch
9
+ # https://developer.github.com/v3/repos/branches/#get-branch
10
+ # GET /repos/:owner/:repo/branches/:branch
11
+ def get_branch(owner:, repo:, branch:)
12
+ response = get(resource: "repos/#{owner}/#{repo}/branches/#{branch}")
13
+ result = Result.new
14
+ result.success = response[:status][:code] == "200"
15
+ result.body = response[:body]
16
+ result.resource = Resource::Branch.build_from_api_result(result)
17
+ result
18
+ end
19
+
20
+ def create_branch(owner:, repo:, dest_branch:, source_branch:)
21
+ result = get_branch(owner: owner, repo: repo, branch: source_branch)
22
+ branch = result.resource
23
+ # TODO: handle errors while retrieving the resource
24
+ parameters = {
25
+ ref: "refs/heads/#{dest_branch}",
26
+ sha: branch.commit["sha"]
27
+ }
28
+ response = post(resource: "repos/#{owner}/#{repo}/git/refs", parameters: parameters)
29
+ result = Result.new
30
+ result.success = response[:status][:code] == "201"
31
+ result.body = response[:body]
32
+ result
33
+ end
34
+
35
+ # Delete a Reference
36
+ # https://developer.github.com/v3/git/refs/#delete-a-reference
37
+ # Example: Deleting a branch:
38
+ # DELETE /repos/octocat/Hello-World/git/refs/heads/feature-a
39
+ def delete_branch(owner:, repo:, branch:)
40
+ response = delete(resource: "repos/#{owner}/#{repo}/git/refs/heads/#{branch}")
41
+ result = Result.new
42
+ result.success = response[:status][:code] == "204"
43
+ result.body = response[:body]
44
+ result
45
+ end
46
+
47
+ end
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,103 @@
1
+ require "base64"
2
+
3
+ module GitWand
4
+ module GitHub
5
+ module API
6
+
7
+ module Commands
8
+ module File
9
+
10
+ # Get contents
11
+ # This method returns the contents of a file or directory in a repository.
12
+ #
13
+ # GET /repos/:owner/:repo/contents/:path
14
+ #
15
+ # | Name | Type | Description |
16
+ # |------|------|-------------|
17
+ # | path | string | The content path. |
18
+ # | ref | string | The name of the commit/branch/tag. Default: the repository’s default branch (usually master) |
19
+ # b8b0a4b3d8dfa9a571353a5c29a9963110d32856
20
+ def get_file(owner:, repo:, path:, ref:)
21
+ parameters = {
22
+ ref: ref
23
+ }
24
+ response = get(resource: "repos/#{owner}/#{repo}/contents/#{path}", query_parameters: parameters)
25
+ result = Result.new
26
+ result.success = response[:status][:code] == "200"
27
+ result.body = response[:body]
28
+ result.resource = Resource::File.build_from_api_result(result)
29
+ result
30
+ end
31
+
32
+ # Update a file
33
+ # PUT /repos/:owner/:repo/contents/:path
34
+ # | Name | Type | Description |
35
+ # |------|------|-------------|
36
+ # | path | string | Required. The content path. |
37
+ # | message | string | Required. The commit message. |
38
+ # | content | string | Required. The updated file content, Base64 encoded. |
39
+ # | sha | string | Required. The blob SHA of the file being replaced. |
40
+ # | branch | string | The branch name. Default: the repository’s default branch (usually master) |
41
+ def update_file(owner:, repo:, path:, message:, content:, branch:)
42
+ result = get_file(owner: owner, repo: repo, path: path, ref: branch)
43
+ # TODO: handle errors while retrieving the resource
44
+ sha = result.body["sha"]
45
+ parameters = {
46
+ message: message,
47
+ content: Base64::encode64(content),
48
+ sha: sha,
49
+ branch: branch,
50
+ }
51
+ response = put(resource: "repos/#{owner}/#{repo}/contents/#{path}", parameters: parameters)
52
+ result = Result.new
53
+ result.success = response[:status][:code] == "200"
54
+ result.body = response[:body]
55
+ result
56
+ end
57
+
58
+ def create_file(owner:, repo:, path:, message:, content:, branch:)
59
+ parameters = {
60
+ message: message,
61
+ content: Base64::encode64(content),
62
+ branch: branch,
63
+ }
64
+ response = put(resource: "repos/#{owner}/#{repo}/contents/#{path}", parameters: parameters)
65
+ result = Result.new
66
+ result.success = response[:status][:code] == "201"
67
+ result.body = response[:body]
68
+ result
69
+ end
70
+
71
+ # Delete a file
72
+ # This method deletes a file in a repository
73
+ #
74
+ # DELETE /repos/:owner/:repo/contents/:path
75
+ #
76
+ # | Name | Type | Description |
77
+ # |------|------|-------------|
78
+ # | path | string | Required. The content path. |
79
+ # | message | string | Required. The commit message. |
80
+ # | sha | string | Required. The blob SHA of the file being replaced. |
81
+ # | branch | string | The branch name. Default: the repository’s default branch (usually master) |
82
+ def delete_file(owner:, repo:, path:, message:, branch:)
83
+ result = get_file(owner: owner, repo: repo, path: path, ref: branch)
84
+ # TODO: handle errors while retrieving the resource
85
+ sha = result.body["sha"]
86
+ parameters = {
87
+ message: message,
88
+ sha: sha,
89
+ branch: branch,
90
+ }
91
+ response = delete(resource: "repos/#{owner}/#{repo}/contents/#{path}", parameters: parameters)
92
+ result = Result.new
93
+ result.success = response[:status][:code] == "200"
94
+ result.body = response[:body]
95
+ result
96
+ end
97
+
98
+ end
99
+ end
100
+
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,87 @@
1
+ module GitWand
2
+ module GitHub
3
+ module API
4
+
5
+ module Commands
6
+ module Issue
7
+
8
+ # List issues for a repository
9
+ # GET /repos/:owner/:repo/issues
10
+ # https://developer.github.com/v3/issues/#list-issues-for-a-repository
11
+ # Parameters
12
+ # | Name | Type | Description |
13
+ # |------|------|-------------|
14
+ # | milestone | integer or string | If an integer is passed, it should refer to a milestone by its number field. If the string * is passed, issues with any milestone are accepted. If the string none is passed, issues without milestones are returned. |
15
+ # | state | string | Indicates the state of the issues to return. Can be either open, closed, or all. Default: open |
16
+ # | assignee | string | Can be the name of a user. Pass in none for issues with no assigned user, and * for issues assigned to any user. |
17
+ # | creator | string | The user that created the issue. |
18
+ # | mentioned | string | A user that's mentioned in the issue. |
19
+ # | labels | string | A list of comma separated label names. Example: bug,ui,@high |
20
+ # | sort | string | What to sort results by. Can be either created, updated, comments. Default: created |
21
+ # | direction | string | The direction of the sort. Can be either asc or desc. Default: desc |
22
+ # | since | string | Only issues updated at or after this time are returned. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. |
23
+ def list_repository_issues(owner:, repo:, milestone: nil, state: nil, assignee: nil, creator: nil, mentioned: nil, labels: [], sort: :created, direction: :desc, since: nil)
24
+ parameters = {}
25
+ parameters[:milestone] = milestone if milestone
26
+ parameters[:state] = state if state
27
+ parameters[:assignee] = assignee if assignee
28
+ parameters[:creator] = creator if creator
29
+ parameters[:mentioned] = mentioned if mentioned
30
+ parameters[:labels] = labels.join(",") if labels.any?
31
+ parameters[:sort] = sort if sort
32
+ parameters[:direction] = direction if direction
33
+ parameters[:since] = since if since
34
+ response = get(resource: "repos/#{owner}/#{repo}/issues", query_parameters: parameters)
35
+ result = Result.new
36
+ result.success = response[:status][:code] == "200"
37
+ result.body = response[:body]
38
+ result.resource = Resource::IssueList.build_from_api_result(result)
39
+ result
40
+ end
41
+
42
+ # Get a single issue
43
+ # https://developer.github.com/v3/issues/#get-a-single-issue
44
+ # GET /repos/:owner/:repo/issues/:number
45
+ def get_issue(owner:, repo:, number:)
46
+ response = get(resource: "repos/#{owner}/#{repo}/issues/#{number}")
47
+ result = Result.new
48
+ result.success = response[:status][:code] == "200"
49
+ result.body = response[:body]
50
+ result.resource = Resource::Issue.build_from_api_result(result)
51
+ result
52
+ end
53
+
54
+ # Create an issue
55
+ # Any user with pull access to a repository can create an issue.
56
+ #
57
+ # POST /repos/:owner/:repo/issues
58
+ #
59
+ # Parameters
60
+ # | Name | Type | Description |
61
+ # |------|------|-------------|
62
+ # | title | string | Required. The title of the issue. |
63
+ # | body | string | The contents of the issue. |
64
+ # | assignee | string | Login for the user that this issue should be assigned to. NOTE: Only users with push access can set the assignee for new issues. The assignee is silently dropped otherwise. This field is deprecated. |
65
+ # | milestone | integer | The number of the milestone to associate this issue with. NOTE: Only users with push access can set the milestone for new issues. The milestone is silently dropped otherwise. |
66
+ # | labels | array | of strings Labels to associate with this issue. NOTE: Only users with push access can set labels for new issues. Labels are silently dropped otherwise. |
67
+ # | assignees | array | of strings Logins for Users to assign to this issue. NOTE: Only users with push access can set assignees for new issues. Assignees are silently dropped otherwise. |
68
+
69
+ def create_issue(owner:, repo:, title:, body:)
70
+ parameters = {
71
+ title: title,
72
+ body: body,
73
+ }
74
+ response = post(resource: "repos/#{owner}/#{repo}/issues", parameters: parameters)
75
+ result = Result.new
76
+ result.success = response[:status][:code] == "201"
77
+ result.body = response[:body]
78
+ result.resource = Resource::Issue.build_from_api_result(result)
79
+ result
80
+ end
81
+
82
+ end
83
+ end
84
+
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,131 @@
1
+ module GitWand
2
+ module GitHub
3
+ module API
4
+
5
+ module Commands
6
+ module PullRequest
7
+
8
+ # List pull requests
9
+ # https://developer.github.com/v3/pulls/#list-pull-requests
10
+ # GET /repos/:owner/:repo/pulls
11
+ # Parameters
12
+ # | Name | Type | Description |
13
+ # |------|------|-------------|
14
+ # | state | string | Either open, closed, or all to filter by state. Default: open |
15
+ # | head | string | Filter pulls by head user and branch name in the format of user:ref-name. Example: github:new-script-format. |
16
+ # | base | string | Filter pulls by base branch name. Example: gh-pages. |
17
+ # | sort | string | What to sort results by. Can be either created, updated, popularity (comment count) or long-running (age, filtering by pulls updated in the last month). Default: created |
18
+ # | direction | string | The direction of the sort. Can be either asc or desc. Default: desc when sort is created or sort is not specified, otherwise asc. |
19
+ def list_pull_requests(owner:, repo:, state: nil, head: nil, base: nil, sort: nil, direction: nil)
20
+ parameters = {
21
+ }
22
+ parameters[:state] = state if state
23
+ parameters[:head] = head if head
24
+ parameters[:base] = base if base
25
+ parameters[:sort] = sort if sort
26
+ parameters[:direction] = direction if direction
27
+ response = get(resource: "repos/#{owner}/#{repo}/pulls", query_parameters: parameters)
28
+ result = Result.new
29
+ result.success = response[:status][:code] == "200"
30
+ result.body = response[:body]
31
+ result.resource = Resource::PullRequestList.build_from_api_result(result)
32
+ result
33
+ end
34
+
35
+ def get_pull_request(owner:, repo:, number:)
36
+ response = get(resource: "repos/#{owner}/#{repo}/pulls/#{number}")
37
+ result = Result.new
38
+ result.success = response[:status][:code] == "200"
39
+ result.body = response[:body]
40
+ result.resource = Resource::PullRequest.build_from_api_result(result)
41
+ result
42
+ end
43
+
44
+ # https://developer.github.com/v3/pulls/#create-a-pull-request
45
+ # | Name | Type | Description |
46
+ # |-------|--------|-------------|
47
+ # | title | string | *Required.* The title of the pull request. |
48
+ # | head | string | *Required.* The name of the branch where your changes are implemented. For cross-repository pull requests in the same network, namespace head with a user like this: username:branch. |
49
+ # | base | string | *Required.* The name of the branch you want the changes pulled into. This should be an existing branch on the current repository. You cannot submit a pull request to one repository that requests a merge to a base of another repository. |
50
+ # | body | string | The contents of the pull request. |
51
+ def create_pull_request(owner:, repo:, title:, head:, base:, body:)
52
+ parameters = {
53
+ title: title,
54
+ head: head,
55
+ base: base,
56
+ body: body,
57
+ }
58
+ raw_create_pull_request(owner: owner, repo: repo, parameters: parameters)
59
+ end
60
+
61
+ def create_pull_request_from_issue(owner:, repo:, head:, base:, issue:)
62
+ parameters = {
63
+ head: head,
64
+ base: base,
65
+ issue: issue,
66
+ }
67
+ raw_create_pull_request(owner: owner, repo: repo, parameters: parameters)
68
+ end
69
+
70
+ def raw_create_pull_request(owner:, repo:, parameters:)
71
+ response = post(resource: "repos/#{owner}/#{repo}/pulls", parameters: parameters)
72
+ result = Result.new
73
+ result.success = response[:status][:code] == "201"
74
+ result.body = response[:body]
75
+ result.resource = Resource::PullRequest.build_from_api_result(result)
76
+ result
77
+ end
78
+
79
+ # TODO
80
+ # Update a PR
81
+ # PATCH /repos/:owner/:repo/pulls/:number
82
+ # | Name | Type | Description |
83
+ # |-------|--------|-------------|
84
+ # | title | string | The title of the pull request. |
85
+ # | body | string | The contents of the pull request. |
86
+ # | state | string | State of this Pull Request. Either open or closed. |
87
+ # | base | string | The name of the branch you want your changes pulled into. This should be an existing branch on the current repository. You cannot update the base branch on a pull request to point to another repository. |
88
+
89
+ # url: https://developer.github.com/v3/pulls/#update-a-pull-request
90
+
91
+ # TODO
92
+ # Get if a pull request has been merged
93
+ # GET /repos/:owner/:repo/pulls/:number/merge
94
+ # is merged: 204
95
+ # is not merged: 404
96
+
97
+ # url: https://developer.github.com/v3/pulls/#get-if-a-pull-request-has-been-merged
98
+
99
+ # Merge a PR
100
+ # url: https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button
101
+ # PUT /repos/:owner/:repo/pulls/:number/merge
102
+ # | Name | Type | Description |
103
+ # |------|------|-------------|
104
+ # | commit_message | string | Extra detail to append to automatic commit message. |
105
+ # | sha | string | SHA that pull request head must match to allow merge |
106
+
107
+ # Response if merge was successful: 200
108
+ # Response if merge cannot be performed: 405
109
+ # Response if sha was provided and pull request head did not match: 409
110
+ def merge_pull_request(owner:, repo:, number:, message:, squash: false)
111
+ result = get_pull_request(owner: owner, repo: repo, number: number)
112
+ pull_request = result.resource
113
+ # TODO: handle errors while retrieving the resource
114
+ parameters = {
115
+ commit_message: message,
116
+ sha: pull_request.head_sha,
117
+ squash: squash,
118
+ }
119
+ response = put(resource: "repos/#{owner}/#{repo}/pulls/#{number}/merge", parameters: parameters)
120
+ result = Result.new
121
+ result.success = response[:status][:code] == "200"
122
+ result.body = response[:body]
123
+ result
124
+ end
125
+
126
+ end
127
+ end
128
+
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,37 @@
1
+ module GitWand
2
+ module GitHub
3
+ module API
4
+
5
+ module Commands
6
+ module Repository
7
+
8
+ def create_repository(name:, description: nil, homepage: nil, auto_init: false, private: false, license: nil)
9
+ parameters = {
10
+ name: name,
11
+ private: private
12
+ }
13
+ parameters[:description] = description if description
14
+ parameters[:homepage] = homepage if homepage
15
+ parameters[:auto_init] = auto_init if auto_init
16
+ parameters[:license] = license if license
17
+ response = post(resource: "user/repos", parameters: parameters)
18
+ result = Result.new
19
+ result.success = response[:status][:code] == "201"
20
+ result.body = response[:body]
21
+ result
22
+ end
23
+
24
+ def delete_repository(name:)
25
+ response = delete(resource: "repos/#{username}/#{name}")
26
+ result = Result.new
27
+ result.success = response[:status][:code] == "204"
28
+ result.body = response[:body]
29
+ result
30
+ end
31
+
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -14,7 +14,7 @@ module GitWand
14
14
 
15
15
  ALLOWED_HTTP_METHODS = %i[get post head put delete options trace patch].to_set
16
16
 
17
- def http_request(resource:, method: :get, client:, parameters: {})
17
+ def http_request(resource:, method: :get, client:, parameters: {}, query_parameters: nil)
18
18
  if ALLOWED_HTTP_METHODS.include?(method)
19
19
  net_http_class = Net::HTTP.const_get(method.to_s.capitalize.to_sym)
20
20
  else
@@ -23,6 +23,9 @@ module GitWand
23
23
  end
24
24
 
25
25
  uri = build_resource_uri(resource)
26
+ if query_parameters
27
+ uri.query = URI.encode_www_form(query_parameters)
28
+ end
26
29
  response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
27
30
  request = net_http_class.new(uri)
28
31
  request["Accept"] = "application/vnd.github.v3+json"
@@ -4,7 +4,7 @@ module GitWand
4
4
 
5
5
  class Result
6
6
 
7
- attr_accessor :success, :body
7
+ attr_accessor :success, :body, :resource
8
8
 
9
9
  def success?
10
10
  @success == true
@@ -0,0 +1,13 @@
1
+ require_relative "resource/branch"
2
+ require_relative "resource/file"
3
+ require_relative "resource/pull_request"
4
+ require_relative "resource/pull_request_list"
5
+ require_relative "resource/issue"
6
+ require_relative "resource/issue_list"
7
+
8
+ module GitWand
9
+ module GitHub
10
+ module Resource
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ module GitWand
2
+ module GitHub
3
+ module Resource
4
+ class Branch
5
+ attr_accessor :name, :commit
6
+
7
+ def self.build_from_api_result(result)
8
+ return unless result.success?
9
+ resource = new
10
+ resource.name = result.body["name"]
11
+ resource.commit = result.body["commit"]
12
+ resource
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ require "base64"
2
+
3
+ module GitWand
4
+ module GitHub
5
+ module Resource
6
+ class File
7
+ attr_accessor :content, :name, :path, :sha, :size, :html_url
8
+
9
+ def self.build_from_api_result(result)
10
+ return unless result.success?
11
+ resource = new
12
+ resource.name = result.body["name"]
13
+ resource.path = result.body["path"]
14
+ resource.sha = result.body["sha"]
15
+ resource.size = result.body["size"]
16
+ resource.html_url = result.body["html_url"]
17
+ resource.content = Base64::decode64(result.body["content"])
18
+ resource
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,50 @@
1
+ require "date"
2
+
3
+ module GitWand
4
+ module GitHub
5
+ module Resource
6
+ class Issue
7
+ attr_accessor :html_url, :number, :state, :title, :body, :user, :labels, :assignee, :locked, :comments_count, :pull_request_reference, :created_at, :updated_at, :closed_at
8
+
9
+ def self.build_from_api_result(result)
10
+ return unless result.success?
11
+ resource = build_from_result_body(result.body)
12
+ end
13
+
14
+ def self.build_from_result_body(result_body)
15
+ resource = new
16
+ resource.html_url = result_body["html_url"]
17
+ resource.number = result_body["number"]
18
+ resource.state = result_body["state"]
19
+ resource.locked = result_body["locked"]
20
+ resource.title = result_body["title"]
21
+ resource.body = result_body["body"]
22
+ resource.user = result_body["user"] # TODO: convert into a User resource
23
+ resource.labels = result_body["labels"] # TODO: convert into a Label resource
24
+ resource.assignee = result_body["assignee"] # TODO: convert into a User resource
25
+ resource.comments_count = result_body["comments"]
26
+ resource.pull_request_reference = result_body["pull_request"]
27
+ resource.created_at = convert_datetime(result_body["created_at"])
28
+ resource.updated_at = convert_datetime(result_body["updated_at"])
29
+ resource.closed_at = convert_datetime(result_body["closed_at"])
30
+ resource
31
+ end
32
+
33
+ def open?
34
+ self.state == "open"
35
+ end
36
+
37
+ def closed?
38
+ self.state == "closed"
39
+ end
40
+
41
+ private
42
+
43
+ def self.convert_datetime(value)
44
+ value && DateTime.parse(value)
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,18 @@
1
+ require "base64"
2
+
3
+ module GitWand
4
+ module GitHub
5
+ module Resource
6
+ class IssueList
7
+
8
+ def self.build_from_api_result(result)
9
+ return unless result.success?
10
+ result.body.map do |body|
11
+ Issue.build_from_result_body(body)
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,48 @@
1
+ require "date"
2
+
3
+ module GitWand
4
+ module GitHub
5
+ module Resource
6
+ class PullRequest
7
+ attr_accessor :html_url, :issue_url, :number, :state, :locked, :title, :user, :body, :created_at, :updated_at, :closed_at, :merged_at, :head_sha
8
+
9
+ def self.build_from_api_result(result)
10
+ return unless result.success?
11
+ resource = build_from_result_body(result.body)
12
+ end
13
+
14
+ def self.build_from_result_body(result_body)
15
+ resource = new
16
+ resource.html_url = result_body["html_url"]
17
+ resource.issue_url = result_body["issue_url"]
18
+ resource.number = result_body["number"]
19
+ resource.title = result_body["title"]
20
+ resource.state = result_body["state"]
21
+ resource.locked = result_body["locked"]
22
+ resource.body = result_body["body"]
23
+ resource.created_at = convert_datetime(result_body["created_at"])
24
+ resource.updated_at = convert_datetime(result_body["updated_at"])
25
+ resource.closed_at = convert_datetime(result_body["closed_at"])
26
+ resource.merged_at = convert_datetime(result_body["merged_at"])
27
+ resource.head_sha = result_body["head"]["sha"]
28
+ resource
29
+ end
30
+
31
+ def open?
32
+ self.state == "open"
33
+ end
34
+
35
+ def closed?
36
+ self.state == "closed"
37
+ end
38
+
39
+ private
40
+
41
+ def self.convert_datetime(value)
42
+ value && DateTime.parse(value)
43
+ end
44
+
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,18 @@
1
+ require "base64"
2
+
3
+ module GitWand
4
+ module GitHub
5
+ module Resource
6
+ class PullRequestList
7
+
8
+ def self.build_from_api_result(result)
9
+ return unless result.success?
10
+ result.body.map do |body|
11
+ PullRequest.build_from_result_body(body)
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module GitWand
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_wand
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maurizio De Magnis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-17 00:00:00.000000000 Z
11
+ date: 2016-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,10 +73,22 @@ files:
73
73
  - git_wand.gemspec
74
74
  - lib/git_wand.rb
75
75
  - lib/git_wand/github/api/client.rb
76
+ - lib/git_wand/github/api/commands/branch.rb
77
+ - lib/git_wand/github/api/commands/file.rb
78
+ - lib/git_wand/github/api/commands/issue.rb
79
+ - lib/git_wand/github/api/commands/pull_request.rb
80
+ - lib/git_wand/github/api/commands/repository.rb
76
81
  - lib/git_wand/github/api/request.rb
77
82
  - lib/git_wand/github/api/response.rb
78
83
  - lib/git_wand/github/api/result.rb
79
84
  - lib/git_wand/github/github.rb
85
+ - lib/git_wand/github/resource.rb
86
+ - lib/git_wand/github/resource/branch.rb
87
+ - lib/git_wand/github/resource/file.rb
88
+ - lib/git_wand/github/resource/issue.rb
89
+ - lib/git_wand/github/resource/issue_list.rb
90
+ - lib/git_wand/github/resource/pull_request.rb
91
+ - lib/git_wand/github/resource/pull_request_list.rb
80
92
  - lib/git_wand/version.rb
81
93
  homepage: https://github.com/olistik/git-wand
82
94
  licenses:
@@ -98,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
110
  version: '0'
99
111
  requirements: []
100
112
  rubyforge_project:
101
- rubygems_version: 2.5.1
113
+ rubygems_version: 2.6.6
102
114
  signing_key:
103
115
  specification_version: 4
104
116
  summary: A Ruby client to the GitHub API.