ghlabel 0.3.0 → 0.4.0

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: 7d313e14a40128d38ca3c0f76cc0f118976726df
4
- data.tar.gz: 401e4ec7d2a7e0e98677b16337786f0c05be1ee7
3
+ metadata.gz: a3dc39e3389a901e0a780af5e9e6d207b8602c02
4
+ data.tar.gz: 6f5e627c35607570b7fe6f6a294394ee09822e37
5
5
  SHA512:
6
- metadata.gz: d58f4dc0abf2c4a77876c9049eeddb5d03736c06f5b5a9de389a983b74c1ece92891615f4baf8cf8ceb861a3384128f047904fa6f4b76b3cff26264bc4426b09
7
- data.tar.gz: 058dbab02658d6a86dcdf337a62d1c337d8d1e8ac6bece44333606fbcf7b0e2db6ffe2eb796a5878354a8d97d932fa7536edca581f5c5b9315783120ec9e949f
6
+ metadata.gz: 6109bbd510aa68ecb5e74df688a1678dca1fb9a36b38a2277747cfd9f2f5077e5ea8663e7bb3f25d575b263eea44f9311e4eb7a1d8b573e54574b19f53f7a79c
7
+ data.tar.gz: d5db8a5c8d31fc7e249f4dbeaf3551e10195bfe1ddf6a78bd2cf8ab8f94c0d5103dd0bed9e7a1f508a0a196ad5b38e6a3c691bd845873395ace5e8a3a03b0575
data/exe/ghlabel CHANGED
@@ -18,13 +18,14 @@ opts = Trollop::options do
18
18
  opt :organization, "Your organization name", default: nil, type: :string
19
19
  opt :add, "--add label1,label2,label3", type: :string, default: nil
20
20
  opt :remove, "--remove label1,label2,label3", type: :string, default: nil
21
+ opt :pr_number, "specify pr number, don't autodetect pr", type: :string, default: nil
21
22
  opt :with_references, "Also apply labels to title referenced #issues_numbers", default: true
22
23
  end
23
24
 
24
25
  abort "You need at least --add or --remove" if opts[:add] && opts[:remove] or !opts[:add] && !opts[:remove]
25
26
 
26
27
  gh = Ghlabel::Ghlabel.new(token: File.read(opts[:token_file]), repo: opts[:repository],
27
- organization: opts[:organization], with_references: opts[:with_references])
28
+ organization: opts[:organization], with_references: opts[:with_references], pr_number: opts[:pr_number])
28
29
 
29
30
  if opts[:remove]
30
31
  labels = opts[:remove].split(',')
@@ -1,3 +1,3 @@
1
1
  module Ghlabel
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/ghlabel.rb CHANGED
@@ -7,18 +7,15 @@ require 'awesome_print'
7
7
 
8
8
  module Ghlabel
9
9
  class Ghlabel
10
- def initialize(token:, repo: nil, organization: nil, with_references: true)
10
+ def initialize(token:, repo: nil, organization: nil, with_references: true, pr_number: nil)
11
11
  @token = token
12
12
  @user = github.users.get.login
13
13
 
14
- if organization.nil? && organizations.count > 1
15
- warn "You have more than one organization (#{organizations}), please choose one as parameter or we'll use your personal one"
16
- end
17
- @organization = organization || @user
18
- @repo = repo || current_repo
14
+ @organization = organization || current_repo_info[:organization]
15
+ @repo = repo || current_repo_info[:repo]
19
16
  @with_references = with_references
20
17
 
21
- @pr = pr_from_ref(File.read('.git/HEAD').gsub('ref: ', '').strip)
18
+ @pr = pr_number ? pr_from_num(pr_number) : pr_from_ref(File.read('.git/HEAD').gsub('ref: ', '').strip)
22
19
  end
23
20
 
24
21
  def remove_labels(labels)
@@ -40,8 +37,15 @@ module Ghlabel
40
37
  end
41
38
 
42
39
  private
40
+
41
+ def pr_from_num(pr_number)
42
+ pr = github.pull_requests.get(user: @organization, repo: @repo, number: pr_number)
43
+ {id: pr.id, ref: pr.head.ref, title: pr.title, created_at: pr.created_at, merged_at: pr.merged_at,
44
+ href: pr['_links']['self']['href'], issue_number: /\/(\d+)$/.match(pr['_links']['issue']['href']).captures.first}
45
+ end
46
+
43
47
  def pr_from_ref(ref)
44
- prs = github.pull_requests.list(user: @organization, repo: @repo, state: 'open', auto_pagination: true)
48
+ prs = github.pull_requests.list(user: @organization, repo: @repo, state: 'all', auto_pagination: true)
45
49
  .map{|x| {id: x.id, ref: x.head.ref, title: x.title, created_at: x.created_at, merged_at: x.merged_at,
46
50
  href: x['_links']['self']['href'], issue_number: /\/(\d+)$/.match(x['_links']['issue']['href']).captures.first }}
47
51
  prs.find{|x| x[:ref] == ref.gsub('refs/heads/', '')}
@@ -52,8 +56,9 @@ module Ghlabel
52
56
  pr_issue.labels.map(&:name)
53
57
  end
54
58
 
55
- def current_repo
56
- @_repo_info ||= (/url = git@github.com:.*\/(.*).git/.match(File.read('.git/config')).captures.try(:first))
59
+ def current_repo_info
60
+ organization, repo = (/url = git@github.com:(.*)\/(.*).git/.match(File.read('.git/config')).captures)
61
+ {organization: organization, repo: repo}
57
62
  end
58
63
 
59
64
  def organizations
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghlabel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pcboy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-13 00:00:00.000000000 Z
11
+ date: 2017-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler