circleci-bundle-update-pr 1.8.4 → 1.9.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
  SHA256:
3
- metadata.gz: 9170b237913a3deea01e25193c6664d3d0ddb1f4cf7b5c1e997d986ed2e539ee
4
- data.tar.gz: 4d2e1ca7f7f74c1bbc2fd17e1a6379b0cb3a373e68add8f2b8f3529b45ec7688
3
+ metadata.gz: 5ebeadf045cb505aea503e22071ab8dde4df038c64e18d7c479194cc25e7a85b
4
+ data.tar.gz: 572f0fa572eb2f2424dec31b0098e5118181fa6048727a7980e647e587668efd
5
5
  SHA512:
6
- metadata.gz: b75132668ee48e8b4706503917c6fcac15f1b61e7e13089f1e0e13efb13fceb884c8cf2a963fb45c9dcd09f77dc9b48c9ab83d9372ae8ad26533e1f92fa237a5
7
- data.tar.gz: 18f821948de58deb560ce6cc23a065ba4431e303063ec96fb56097e24eb1b037b399ec93c71b223c7ec8844e7bb6400dd7eccbbc17c8f039c1e818f283989e13
6
+ metadata.gz: 6d738b9eb1c37c9cbfdb7a050befbce82c2537f0b0cdb7430d6ab4fe6a9791f482d20bf1e9777d57d49bc923d121b044e31c040001344a7b0b2a8444c80329eb
7
+ data.tar.gz: 9eef3680614f7a294c996202e64af2f1c99795c31ff300b0b2cb9cfc16913f606938b900771156883e016156f4412c8220972d7ea40296a5ccb91451e3631822
data/.gitignore CHANGED
@@ -1,4 +1,3 @@
1
1
  /.bundle
2
- /.envrc
3
2
  /pkg
4
3
  /vendor/bundle
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- circleci-bundle-update-pr (1.8.4)
5
- compare_linker
4
+ circleci-bundle-update-pr (1.9.0)
5
+ compare_linker (>= 1.4.0)
6
6
  octokit
7
7
 
8
8
  GEM
@@ -13,11 +13,11 @@ GEM
13
13
  compare_linker (1.4.0)
14
14
  httpclient
15
15
  octokit
16
- faraday (0.14.0)
16
+ faraday (0.15.2)
17
17
  multipart-post (>= 1.2, < 3)
18
18
  httpclient (2.8.3)
19
19
  multipart-post (2.0.0)
20
- octokit (4.8.0)
20
+ octokit (4.9.0)
21
21
  sawyer (~> 0.8.0, >= 0.5.3)
22
22
  public_suffix (3.0.2)
23
23
  rake (12.3.1)
@@ -36,4 +36,4 @@ DEPENDENCIES
36
36
  rake
37
37
 
38
38
  BUNDLED WITH
39
- 1.16.1
39
+ 1.16.2
@@ -31,6 +31,9 @@ GitHub personal access token is required for sending pull requests to your repos
31
31
  1. Go to [your account's settings page](https://github.com/settings/tokens) and generate a personal access token with "repo" scope
32
32
  2. On CircleCI dashboard, go to your application's "Project Settings" -> "Environment Variables"
33
33
  3. Add an environment variable `GITHUB_ACCESS_TOKEN` with your GitHub personal access token
34
+ * If use GitHub Enterprise
35
+ * `ENTERPRISE_OCTOKIT_ACCESS_TOKEN` with your GitHub Enterprise personal access token
36
+ * `ENTERPRISE_OCTOKIT_API_ENDPOINT` with your GitHub Enterprise api endpoint (e.g. https://www.example.com/api/v3)
34
37
 
35
38
  ### Getting CircleCI API token
36
39
 
data/README.md CHANGED
@@ -33,6 +33,9 @@ GitHub personal access token is required for sending pull requests to your repos
33
33
  1. Go to [your account's settings page](https://github.com/settings/tokens) and generate a personal access token with "repo" scope
34
34
  2. On CircleCI dashboard, go to your application's "Project Settings" -> "Environment Variables"
35
35
  3. Add an environment variable `GITHUB_ACCESS_TOKEN` with your GitHub personal access token
36
+ * If use GitHub Enterprise
37
+ * `ENTERPRISE_OCTOKIT_ACCESS_TOKEN` with your GitHub Enterprise personal access token
38
+ * `ENTERPRISE_OCTOKIT_API_ENDPOINT` with your GitHub Enterprise api endpoint (e.g. https://www.example.com/api/v3)
36
39
 
37
40
  ### Configure circle.yml
38
41
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency 'octokit'
21
- spec.add_dependency 'compare_linker'
21
+ spec.add_dependency 'compare_linker', ">= 1.4.0"
22
22
 
23
23
  spec.add_development_dependency "bundler"
24
24
  spec.add_development_dependency "rake"
@@ -7,16 +7,14 @@ module Circleci
7
7
  module Update
8
8
  module Pr
9
9
  def self.create_if_needed(git_username: nil, git_email: nil, git_branches: ["master"])
10
- raise "$CIRCLE_PROJECT_USERNAME isn't set" unless ENV['CIRCLE_PROJECT_USERNAME']
11
- raise "$CIRCLE_PROJECT_REPONAME isn't set" unless ENV['CIRCLE_PROJECT_REPONAME']
12
- raise "$GITHUB_ACCESS_TOKEN isn't set" unless ENV['GITHUB_ACCESS_TOKEN']
10
+ raise_if_env_unvalid!
13
11
  return unless need?(git_branches)
14
12
  repo_full_name = "#{ENV['CIRCLE_PROJECT_USERNAME']}/#{ENV['CIRCLE_PROJECT_REPONAME']}"
15
13
  now = Time.now
16
14
  branch = "bundle-update-#{now.strftime('%Y%m%d%H%M%S')}"
17
15
 
18
16
  git_username ||= client.user.login
19
- git_email ||= "#{git_username}@users.noreply.github.com"
17
+ git_email ||= "#{git_username}@users.noreply.#{github_host}"
20
18
 
21
19
  create_branch(git_username, git_email, branch, repo_full_name)
22
20
  pull_request = create_pull_request(repo_full_name, branch, now)
@@ -33,7 +31,7 @@ module Circleci
33
31
  private_class_method :need?
34
32
 
35
33
  def self.create_branch(git_username, git_email, branch, repo_full_name)
36
- remote = "https://#{ENV["GITHUB_ACCESS_TOKEN"]}@github.com/#{repo_full_name}"
34
+ remote = "https://#{github_access_token}@#{github_host}/#{repo_full_name}"
37
35
  system("git remote add github-url-with-token #{remote}")
38
36
  system("git config user.name #{git_username}")
39
37
  system("git config user.email #{git_email}")
@@ -46,7 +44,8 @@ module Circleci
46
44
 
47
45
  def self.create_pull_request(repo_full_name, branch, now)
48
46
  title = "bundle update at #{now.strftime('%Y-%m-%d %H:%M:%S %Z')}"
49
- body = "auto generated by [CircleCI of #{ENV['CIRCLE_PROJECT_REPONAME']}](https://circleci.com/gh/#{repo_full_name})"
47
+ build_url = URI.parse ENV['CIRCLE_BUILD_URL']
48
+ body = "auto generated by [CircleCI of #{ENV['CIRCLE_PROJECT_REPONAME']}](https://#{build_url.host}/gh/#{repo_full_name})"
50
49
  client.create_pull_request(repo_full_name, ENV['CIRCLE_BRANCH'], branch, title, body)
51
50
  end
52
51
  private_class_method :create_pull_request
@@ -63,15 +62,51 @@ module Circleci
63
62
 
64
63
  Powered by [compare_linker](https://rubygems.org/gems/compare_linker)
65
64
  EOC
66
-
67
65
  compare_linker.add_comment(repo_full_name, pr_number, comment)
68
66
  end
69
67
  private_class_method :add_comment_of_compare_linker
70
68
 
71
69
  def self.client
72
- Octokit::Client.new(access_token: ENV["GITHUB_ACCESS_TOKEN"])
70
+ if enterprise?
71
+ Octokit::Client.new(access_token: ENV['ENTERPRISE_OCTOKIT_ACCESS_TOKEN'],
72
+ api_endpoint: ENV['ENTERPRISE_OCTOKIT_API_ENDPOINT'])
73
+ else
74
+ Octokit::Client.new(access_token: ENV["GITHUB_ACCESS_TOKEN"])
75
+ end
73
76
  end
74
77
  private_class_method :client
78
+
79
+ def self.enterprise?
80
+ !!ENV['ENTERPRISE_OCTOKIT_ACCESS_TOKEN']
81
+ end
82
+ private_class_method :enterprise?
83
+
84
+ def self.github_access_token
85
+ enterprise? ? ENV['ENTERPRISE_OCTOKIT_ACCESS_TOKEN'] : ENV['GITHUB_ACCESS_TOKEN']
86
+ end
87
+ private_class_method :github_access_token
88
+
89
+ def self.github_host
90
+ # A format like git@github.com:masutaka/compare_linker.git
91
+ return $1 if ENV['CIRCLE_REPOSITORY_URL'] =~ %r{([^@]+?):}
92
+ # A format like https://github.com/masutaka/circleci-bundle-update-pr.git
93
+ return $1 if ENV['CIRCLE_REPOSITORY_URL'] =~ %r{https://(.+?)/}
94
+ 'github.com'
95
+ end
96
+ private_class_method :github_host
97
+
98
+ def self.raise_if_env_unvalid!
99
+ raise "$CIRCLE_PROJECT_USERNAME isn't set" unless ENV['CIRCLE_PROJECT_USERNAME']
100
+ raise "$CIRCLE_PROJECT_REPONAME isn't set" unless ENV['CIRCLE_PROJECT_REPONAME']
101
+ raise "$GITHUB_ACCESS_TOKEN isn't set" unless ENV['GITHUB_ACCESS_TOKEN']
102
+ if ENV['ENTERPRISE_OCTOKIT_ACCESS_TOKEN'] && !ENV['ENTERPRISE_OCTOKIT_API_ENDPOINT']
103
+ raise "$ENTERPRISE_OCTOKIT_API_ENDPOINT isn't set"
104
+ end
105
+ if !ENV['ENTERPRISE_OCTOKIT_ACCESS_TOKEN'] && ENV['ENTERPRISE_OCTOKIT_API_ENDPOINT']
106
+ raise "$ENTERPRISE_OCTOKIT_ACCESS_TOKEN isn't set"
107
+ end
108
+ end
109
+ private_class_method :raise_if_env_unvalid!
75
110
  end
76
111
  end
77
112
  end
@@ -2,7 +2,7 @@ module Circleci
2
2
  module Bundle
3
3
  module Update
4
4
  module Pr
5
- VERSION = "1.8.4"
5
+ VERSION = "1.9.0"
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circleci-bundle-update-pr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.4
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Masuda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-03 00:00:00.000000000 Z
11
+ date: 2018-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 1.4.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 1.4.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement