File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,10 @@ env_pull.pull_request_id #=> 800
2525 * ` ENV['TRAVIS_PULL_REQUEST'] `
2626 * [ Environment Variables - Travis CI] ( http://docs.travis-ci.com/user/environment-variables/#Convenience-Variables )
2727
28+ * CircleCI
29+ * ` ENV['CIRCLE_PR_NUMBER'] `
30+ * [ Environment variables - CircleCI] ( https://circleci.com/docs/environment-variables#building-pull-requests-that-come-from-forks )
31+
2832
2933## Changelog
3034
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ def initialize
99 def fetch_pull_request_id
1010 if ENV [ 'TRAVIS_PULL_REQUEST' ] && ENV [ 'TRAVIS_PULL_REQUEST' ] . downcase != 'false'
1111 ENV [ 'TRAVIS_PULL_REQUEST' ] . to_i
12+ elsif ENV [ 'CIRCLE_PR_NUMBER' ]
13+ ENV [ 'CIRCLE_PR_NUMBER' ] . to_i
1214 end
1315 end
1416
Original file line number Diff line number Diff line change @@ -4,11 +4,14 @@ module EnvPullRequest
44 class TestCi < Test ::Unit ::TestCase
55 def self . startup
66 @original_travis_pull_request = ENV [ 'TRAVIS_PULL_REQUEST' ]
7+ @original_circle_pr_number = ENV [ 'CIRCLE_PR_NUMBER' ]
78 ENV . delete 'TRAVIS_PULL_REQUEST'
9+ ENV . delete 'CIRCLE_PR_NUMBER'
810 end
911
1012 def self . shutdown
1113 ENV [ 'TRAVIS_PULL_REQUEST' ] = @original_travis_pull_request
14+ ENV [ 'CIRCLE_PR_NUMBER' ] = @original_circle_pr_number
1215 end
1316
1417 sub_test_case 'not pull request' do
@@ -45,5 +48,27 @@ def self.shutdown
4548 end
4649 end
4750 end
51+
52+ sub_test_case 'circle ci' do
53+ pull_id = 800
54+ setup do
55+ ENV [ 'CIRCLE_PR_NUMBER' ] = pull_id . to_s
56+ end
57+
58+ teardown do
59+ ENV . delete 'CIRCLE_PR_NUMBER'
60+ end
61+
62+ test '#pull_request?' do
63+ assert do
64+ EnvPullRequest . new . pull_request? == true
65+ end
66+ end
67+ test '#pull_request_id' do
68+ assert do
69+ EnvPullRequest . new . pull_request_id == pull_id
70+ end
71+ end
72+ end
4873 end
4974end
You can’t perform that action at this time.
0 commit comments