pully 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac6ecacdbc362f4fc022fc9fa9fa2d81013a25fa
4
- data.tar.gz: 1c878608104e3d72f23702a2f153382c11fccc11
3
+ metadata.gz: 60cb6b722172142529c46b79835a40df267f064a
4
+ data.tar.gz: 04c49a7512ea7c1eb87f1b693afb7bdb0ab2e09a
5
5
  SHA512:
6
- metadata.gz: 2c6131eabbc8ba34f82a79c0a39de726c50cfa5716a039921cfb2d3cd84284b7b3ce0d227596a7044ad95e307683ae54369ccdd86a6e0b383d8e12fd21e770d4
7
- data.tar.gz: 2497f645f7e725aec7a42812de990f69061f297280ce70ff2483676ce2c2f9bb26363eff0bfabe728696dc111dca677c17920b707a0e1e31a1451f5c01376cc6
6
+ metadata.gz: 5b751f7a8ffdb0c564c2e9eb31c8fd7a8eb94266c3046c190f66e6c5b7dd50846c4d363706ba016cae3d607f347dfe586cb0839a8838bf868ba3b84d56bcd72a
7
+ data.tar.gz: 8ae2840d65a0449645563ac2a7a50276c95ad187fe14057239d41f11df447529444e9446ded01be499394e9cd6743050af758e146cd60107419fcd152715d9a7
data/README.md CHANGED
@@ -14,7 +14,7 @@ A work in progress
14
14
  require 'pully'
15
15
 
16
16
  #Create a new pully object, each pully object targets (1) repository.
17
- pully = Pully.new("github_username", "github_password", "my_repository")
17
+ pully = Pully.new(user:"github_username", pass:"github_password", repo:"my_repository")
18
18
 
19
19
  #Create a new pull request to merge 'my_branch' into 'master' with the title 'My pull request' and the message 'Hey XXX...'
20
20
  pull_number = pully.create_pull_request(from:"my_branch", to:"master", subject:"My pull request", message:"Hey XXXX, can you merge this for me?")
@@ -26,6 +26,16 @@ pully.write_comment_to_pull_request(pull_number, "Test Comment")
26
26
  comments = pully.comments_for_pull_request(pull_number)
27
27
  ```
28
28
 
29
+ # Organization / Repositories not owned by you
30
+ If your repositories are not owner by you, i.e. they are owned by an organization or another user who has granted you permissions, you will need to
31
+ pass the `owner` field for the other individual or organization.
32
+
33
+ ```ruby
34
+ #Create a new pully object, each pully object targets (1) repository in an organization.
35
+ pully = Pully.new(user:"github_username", pass:"github_password", repo:"my_repository", owner:"my_organization")
36
+
37
+ ```
38
+
29
39
  ## Requirements
30
40
 
31
41
  - Ruby 2.1 or Higher
data/lib/pully/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pully
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/pully.rb CHANGED
@@ -1,27 +1,34 @@
1
1
  require "pully/version"
2
- require 'ghee'
3
2
  require 'octokit'
4
3
  require 'git'
5
4
  require 'tempfile'
6
5
 
7
6
  module Pully
8
7
  class Pully
9
- def initialize(user:, pass:, repo:)
8
+ module Error
9
+ class NonExistantRepository < StandardError; end
10
+ class BadLogin < StandardError; end
11
+ end
12
+
13
+ def initialize(user:, pass:, repo:, owner:)
10
14
  @user = user
11
15
  @pass = pass
12
16
  @repo = repo
13
- @repo_selector = "#{@user}/#{@repo}"
17
+ @owner = owner
18
+ @repo_selector = @owner ? "#{@owner}/#{@repo}" : "#{@user}/#{@repo}"
14
19
 
15
- @ghee = Ghee.basic_auth(@user, @pass)
16
20
  @gh_client = Octokit::Client.new(:login => @user, :password => @pass)
17
21
 
18
- #Test authentication, to_s required to have side-effects
19
- @ghee.repos(user, repo).to_s
20
- @gh_client.user #throw exception if auth is bad
22
+ begin
23
+ @gh_client.user #throw exception if auth is bad
24
+ rescue Octokit::Unauthorized
25
+ raise Error::BadLogin
26
+ end
27
+ raise Error::NonExistantRepository unless @gh_client.repository?(@repo_selector)
21
28
  end
22
29
 
23
30
  def create_pull_request(from:, to:, subject:, message:)
24
- @ghee.repos(@user, @repo).pulls.create(:title => subject, :body => message, :base => to, :head => from)["number"]
31
+ @gh_client.create_pull_request(@repo_selector, to, from, subject, message)["number"]
25
32
  end
26
33
 
27
34
  def comments_for_pull_request pull_number
@@ -49,7 +56,6 @@ module Pully
49
56
  @repo_selector = repo_selector
50
57
  @clone_url = clone_url
51
58
 
52
-
53
59
  #Setup the local git client
54
60
  ##############################################################
55
61
  Git.configure do |config|
@@ -135,7 +141,7 @@ module Pully
135
141
  end
136
142
  end
137
143
 
138
- def self.new(user:, pass:, repo:)
139
- Pully.new(user: user, pass: pass, repo: repo)
144
+ def self.new(user:, pass:, repo:, owner: nil)
145
+ Pully.new(user: user, pass: pass, repo: repo, owner: owner)
140
146
  end
141
147
  end
data/spec/assets/test.yml CHANGED
@@ -3,3 +3,6 @@ github:
3
3
  pass: pully-test-account0
4
4
  repo: pully-test-account
5
5
  clone_url: git@github.com:pully-test-account/pully-test-account.git
6
+ org_owner: pully-test-organization
7
+ org_repo: pully-test-organization
8
+ org_clone_url: git@github.com:pully-test-organization/pully-test-organization.git
data/spec/lib_spec.rb CHANGED
@@ -9,18 +9,31 @@ def gh_info
9
9
  end
10
10
 
11
11
  RSpec.describe "Library" do
12
+ def repo_selector(user:, repo:, owner:)
13
+ return "#{user}/#{repo}" unless owner
14
+ return "#{owner}/#{repo}"
15
+ end
16
+
12
17
  it "Does throw an exception with INcorrect credentials while creating an object" do
13
- expect { pully = Pully.new(user: "abcdefgh", pass: "abcdefgh", repo: "abcdefgh") }.to raise_error(Ghee::Unauthorized)
18
+ expect { pully = Pully.new(user: "abcdefgh", pass: "abcdefgh", repo: "abcdefgh") }.to raise_error(Pully::Pully::Error::BadLogin)
14
19
  end
15
20
 
16
21
  it "Does NOT throw an exception with correct credentials while creating an object" do
17
22
  pully = Pully.new(user: gh_info["user"], pass: gh_info["pass"], repo: gh_info["repo"])
18
23
  end
19
24
 
25
+ it "DOES throw an exception with correct credentials while creating an object but with a non-existant repository" do
26
+ expect { pully = Pully.new(user: gh_info["user"], pass: gh_info["pass"], repo: SecureRandom.hex) }.to raise_error(Pully::Pully::Error::NonExistantRepository)
27
+ end
28
+
29
+ #it "Does throw an exception with correct credentials while creating an object with an alternate owner but without specifying that owner" do
30
+ #expect { pully = Pully.new(user: gh_info["user"], pass: gh_info["pass"], repo: gh_info["org_repo"])}.to raise_error
31
+ #end
32
+
20
33
  it "Can call create a new pull request and returns an integer for the pull request #" do
21
34
  #test branch creator
22
35
  new_branch_name = SecureRandom.hex
23
- th = Pully::TestHelpers::Branch.new(user: gh_info["user"], pass: gh_info["pass"], repo_selector: repo_selector, clone_url: gh_info["clone_url"])
36
+ th = Pully::TestHelpers::Branch.new(user: gh_info["user"], pass: gh_info["pass"], repo_selector: repo_selector(user: gh_info["user"], repo: gh_info["repo"], owner:nil), clone_url: gh_info["clone_url"])
24
37
  th.create_branch(new_branch_name)
25
38
  th.commit_new_random_file(new_branch_name)
26
39
 
@@ -31,10 +44,24 @@ RSpec.describe "Library" do
31
44
  th.delete_branch(new_branch_name)
32
45
  end
33
46
 
47
+ it "Can call create a new pull request for an organization repo and returns an integer for the pull request #" do
48
+ #test branch creator
49
+ new_branch_name = SecureRandom.hex
50
+ th = Pully::TestHelpers::Branch.new(user: gh_info["user"], pass: gh_info["pass"], repo_selector: repo_selector(user: gh_info["user"], repo: gh_info["org_repo"], owner:gh_info["org_owner"]), clone_url: gh_info["org_clone_url"])
51
+ th.create_branch(new_branch_name)
52
+ th.commit_new_random_file(new_branch_name)
53
+
54
+ pully = Pully.new(user: gh_info["user"], pass: gh_info["pass"], repo: gh_info["org_repo"], owner: gh_info["org_owner"])
55
+ n = pully.create_pull_request(from:new_branch_name, to:"master", subject:"My pull request", message:"Hey XXXX, can you merge this for me?")
56
+ expect(n.class).to be(Fixnum)
57
+
58
+ th.delete_branch(new_branch_name)
59
+ end
60
+
34
61
  it "Can call create a new pull request and write a comment on that pull request" do
35
62
  #test branch creator
36
63
  new_branch_name = SecureRandom.hex
37
- th = Pully::TestHelpers::Branch.new(user: gh_info["user"], pass: gh_info["pass"], repo_selector: repo_selector, clone_url: gh_info["clone_url"])
64
+ th = Pully::TestHelpers::Branch.new(user: gh_info["user"], pass: gh_info["pass"], repo_selector: repo_selector(user: gh_info["user"], repo: gh_info["repo"], owner:nil), clone_url: gh_info["clone_url"])
38
65
  th.create_branch(new_branch_name)
39
66
  th.commit_new_random_file(new_branch_name)
40
67
 
@@ -49,4 +76,23 @@ RSpec.describe "Library" do
49
76
 
50
77
  th.delete_branch(new_branch_name)
51
78
  end
79
+
80
+ it "Can call create a new pull request and write a comment on that pull request for an organization" do
81
+ #test branch creator
82
+ new_branch_name = SecureRandom.hex
83
+ th = Pully::TestHelpers::Branch.new(user: gh_info["user"], pass: gh_info["pass"], repo_selector: repo_selector(user: gh_info["user"], repo: gh_info["org_repo"], owner:gh_info["org_owner"]), clone_url: gh_info["org_clone_url"])
84
+ th.create_branch(new_branch_name)
85
+ th.commit_new_random_file(new_branch_name)
86
+
87
+ pully = Pully.new(user: gh_info["user"], pass: gh_info["pass"], repo: gh_info["org_repo"], owner: gh_info["org_owner"])
88
+ pull_number = pully.create_pull_request(from:new_branch_name, to:"master", subject:"My pull request", message:"Hey XXXX, can you merge this for me?")
89
+
90
+ before_create = pully.comments_for_pull_request(pull_number).length
91
+ pully.write_comment_to_pull_request(pull_number, "Test Comment")
92
+ after_create = pully.comments_for_pull_request(pull_number).length
93
+
94
+ expect(after_create).to eq(before_create+1)
95
+
96
+ th.delete_branch(new_branch_name)
97
+ end
52
98
  end
@@ -3,21 +3,22 @@ require 'ghee'
3
3
  require './lib/pully.rb'
4
4
  require 'securerandom'
5
5
 
6
- #Get github information
7
- def gh_info
8
- yaml = YAML.load_file("./spec/assets/test.yml")
9
- return yaml["github"]
10
- end
11
6
 
12
- def repo_selector
13
- return "#{gh_info["user"]}/#{gh_info["repo"]}"
14
- end
7
+ RSpec.describe "Test Library" do
8
+ #Get github information
9
+ def gh_info
10
+ yaml = YAML.load_file("./spec/assets/test.yml")
11
+ return yaml["github"]
12
+ end
15
13
 
16
- def rand_repo_selector
17
- return "#{gh_info["user"]}/#{SecureRandom.hex}"
18
- end
14
+ def repo_selector
15
+ return "#{gh_info["user"]}/#{gh_info["repo"]}"
16
+ end
17
+
18
+ def rand_repo_selector
19
+ return "#{gh_info["user"]}/#{SecureRandom.hex}"
20
+ end
19
21
 
20
- RSpec.describe "Test Library" do
21
22
  it "Fails creation with incorrect credentials" do
22
23
  expect { Pully::TestHelpers::Branch.new(user: SecureRandom.hex, pass: SecureRandom.hex, repo_selector: repo_selector, clone_url: gh_info["clone_url"]) }.to raise_error(Pully::TestHelpers::Branch::Error::BadLogin)
23
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pully
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seo Townsend