appveyor-api 0.0.1

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.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.circle.yml +8 -0
  3. data/.github/CONTRIBUTING.md +5 -0
  4. data/.gitignore +50 -0
  5. data/.rubocop.yml +10 -0
  6. data/.ruby-version +1 -0
  7. data/Gemfile +5 -0
  8. data/Gemfile.lock +112 -0
  9. data/Guardfile +22 -0
  10. data/LICENSE +674 -0
  11. data/README.md +26 -0
  12. data/appveyor.gemspec +37 -0
  13. data/lib/appveyor-api.rb +6 -0
  14. data/lib/appveyor-api/build.rb +34 -0
  15. data/lib/appveyor-api/client.rb +78 -0
  16. data/lib/appveyor-api/collaborators.rb +21 -0
  17. data/lib/appveyor-api/deployment.rb +47 -0
  18. data/lib/appveyor-api/environments.rb +116 -0
  19. data/lib/appveyor-api/projects.rb +116 -0
  20. data/lib/appveyor-api/response.rb +26 -0
  21. data/lib/appveyor-api/roles.rb +17 -0
  22. data/lib/appveyor-api/users.rb +24 -0
  23. data/spec/appveyor-api/client_spec.rb +16 -0
  24. data/spec/appveyor-api/environment_spec.rb +153 -0
  25. data/spec/appveyor-api/environments_spec.rb +48 -0
  26. data/spec/appveyor-api/project_spec.rb +109 -0
  27. data/spec/cassettes/add_FTP_environment_cassette.yml +49 -0
  28. data/spec/cassettes/create_environment_cassette.yml +49 -0
  29. data/spec/cassettes/delete_environment.yml +42 -0
  30. data/spec/cassettes/dev_environment_cassette.yml +93 -0
  31. data/spec/cassettes/environment_12168.yml +47 -0
  32. data/spec/cassettes/environment_cassette.yml +93 -0
  33. data/spec/cassettes/environment_list_after_delete.yml +46 -0
  34. data/spec/cassettes/environment_list_cassette.yml +49 -0
  35. data/spec/cassettes/find_environment_12168.yml +47 -0
  36. data/spec/cassettes/find_production_environment.yml +95 -0
  37. data/spec/cassettes/project_list.yml +60 -0
  38. data/spec/cassettes/projects_list.yml +288 -0
  39. data/spec/cassettes/update_FTP_environment_cassette.yml +49 -0
  40. data/spec/cassettes/update_environment_cassette.yml +49 -0
  41. data/spec/spec_helper.rb +28 -0
  42. metadata +299 -0
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ module AppVeyor
3
+ # Response from request
4
+ #
5
+ class Response
6
+ def initialize(faraday_response)
7
+ @raw_body = faraday_response.body
8
+ @raw_headers = faraday_response.headers
9
+ @raw_status = faraday_response.status
10
+ end
11
+
12
+ def body
13
+ @raw_body
14
+ end
15
+
16
+ def headers
17
+ @headers ||= @raw_headers.inject({}) do |result, (key, value)|
18
+ result.merge(key.split('-').map(&:capitalize).join('-') => value)
19
+ end
20
+ end
21
+
22
+ def status
23
+ @raw_status
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ # Roles
3
+
4
+ def roles
5
+ end
6
+
7
+ def role
8
+ end
9
+
10
+ def add_role
11
+ end
12
+
13
+ def update_role
14
+ end
15
+
16
+ def delete_role
17
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ # Users
3
+ def get_users(config)
4
+ # HTTParty.get('https://ci.appveyor.com/api/users',
5
+ # headers: { 'Authorization' => "Bearer #{config.api_token}" })
6
+ end
7
+
8
+ def get_user(config, user_id)
9
+ # HTTParty.get("https://ci.appveyor.com/api/user/#{userId}",
10
+ # headers: { 'Authorization' => "Bearer #{config.api_token}" })
11
+ end
12
+
13
+ def add_user(config, user)
14
+ # HTTParty.get("https://ci.appveyor.com/api/user/#{userId}",
15
+ # headers: { 'Authorization' => "Bearer #{config.api_token}" })
16
+ end
17
+
18
+ def update_user(config, user)
19
+ # PUT /api/users
20
+ end
21
+
22
+ def delete_user(config, user_id)
23
+ # DELETE /api/users/{userId}
24
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe AppVeyor::Client do
5
+ before(:each) do
6
+ @client = AppVeyor::Client.new(access_token: 'test_token')
7
+ end
8
+
9
+ it 'should exist' do
10
+ expect(@client).to be_an_instance_of(AppVeyor::Client)
11
+ end
12
+
13
+ it 'should return an access_token' do
14
+ expect(@client.access_token).to match('test_token')
15
+ end
16
+ end
@@ -0,0 +1,153 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.context AppVeyor::Environment do
4
+ describe 'Stubbed environment' do
5
+ describe 'test' do
6
+ before :each do
7
+ @environment = AppVeyor::Environment.new('deploymentEnvironmentId' => 10_989,
8
+ 'accountId' => 56_787,
9
+ 'provider' => 'Agent',
10
+ 'name' => 'test',
11
+ 'settings' =>
12
+ { 'providerSettings' =>
13
+ [{
14
+ 'name' => 'test_setting',
15
+ 'value' => {
16
+ 'isEncrypted' => false,
17
+ 'value' => 'myaccount'
18
+ }
19
+ },
20
+ {
21
+ 'name' => 'test_setting_2',
22
+ 'value' => {
23
+ 'isEncrypted' => true,
24
+ 'value' => '1234567890'
25
+ }
26
+ }]
27
+ })
28
+ end
29
+ it 'should have a name' do
30
+ expect(@environment).to respond_to(:name)
31
+ expect(@environment.name).to match('test')
32
+ end
33
+
34
+ it 'should have an id' do
35
+ expect(@environment.id).to match(10_989)
36
+ end
37
+
38
+ it 'should have an account id' do
39
+ expect(@environment.account_id).to match(56_787)
40
+ end
41
+
42
+ it 'should have an Agent provider' do
43
+ expect(@environment.provider).to match('Agent')
44
+ end
45
+
46
+ it 'should have an unencrypted Test Setting' do
47
+ expect(@environment.settings['providerSettings'][0]['name']).to match('test_setting')
48
+ expect(@environment.settings['providerSettings'][0]['value']['value']).to match('myaccount')
49
+ expect(@environment.settings['providerSettings'][0]['value']['isEncrypted']).to be(false)
50
+ end
51
+
52
+ it 'should have an encrypted Setting' do
53
+ expect(@environment.settings['providerSettings'][1]['name']).to match('test_setting_2')
54
+ expect(@environment.settings['providerSettings'][1]['value']['value']).to match('1234567890')
55
+ expect(@environment.settings['providerSettings'][1]['value']['isEncrypted']).to be(true)
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ RSpec.context AppVeyor::Client do
62
+ describe 'Create Environment' do
63
+ before :each do
64
+ @client = AppVeyor::Client.new
65
+ @environment = AppVeyor::Environment.new('deploymentEnvironmentId' => 10_989,
66
+ 'accountId' => 56_787,
67
+ 'provider' => 'Agent',
68
+ 'name' => 'test',
69
+ 'settings' =>
70
+ { 'providerSettings' =>
71
+ [{
72
+ 'name' => 'test_setting',
73
+ 'value' => {
74
+ 'isEncrypted' => false,
75
+ 'value' => 'myaccount'
76
+ }
77
+ },
78
+ {
79
+ 'name' => 'test_setting_2',
80
+ 'value' => {
81
+ 'isEncrypted' => true,
82
+ 'value' => '1234567890'
83
+ }
84
+ }]
85
+ })
86
+ # rubocop:disable Metrics/LineLength
87
+
88
+ @e={"name":"production","provider":"FTP","settings":{"providerSettings":[{"name":"server","value":{"value":"ftp.myserver.com","isEncrypted":false}},{"name":"username","value":{"value":"ftp-user","isEncrypted":false}},{"name":"password","value":{"value":"password","isEncrypted":true}}],"environmentVariables":[{"name":"my-var","value":{"value":"123","isEncrypted":false}}]}}
89
+ # rubocop:enable Metrics/LineLength
90
+ end
91
+
92
+ it 'should be able to create an environment' do
93
+ expect(@client).to respond_to(:create_environment)
94
+ end
95
+
96
+ it 'should return an environment' do
97
+ VCR.use_cassette('create environment cassette') do
98
+ expect(@client.create_environment(@e)).to be_an_instance_of(AppVeyor::Environment)
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ RSpec.context AppVeyor::Client do
105
+ describe 'Update Environment' do
106
+ before :each do
107
+ # rubocop:disable Metrics/LineLength
108
+ @e1={"deploymentEnvironmentId":12168,"name":"production","provider":"FTP","settings":{"providerSettings":[{"name":"server","value":{"value":"ftp.server.com","isEncrypted":false}},{"name":"username","value":{"value":"ftp-user","isEncrypted":false}},{"name":"password","value":{"value":"password","isEncrypted":true}}],"environmentVariables":[{"name":"my-var","value":{"value":"123","isEncrypted":false}}]}}
109
+ @e2={"deploymentEnvironmentId":12168,"name":"production","provider":"FTP","settings":{"providerSettings":[{"name":"server","value":{"value":"ftp.acme.com","isEncrypted":false}},{"name":"username","value":{"value":"ftp-user","isEncrypted":false}},{"name":"password","value":{"value":"password","isEncrypted":true}}],"environmentVariables":[{"name":"my-var","value":{"value":"123","isEncrypted":false}}]}}
110
+ # rubocop:enable Metrics/LineLength
111
+ @client = AppVeyor::Client.new
112
+ end
113
+
114
+ it 'should be able to update an environment' do
115
+ expect(@client).to respond_to(:update_environment)
116
+ end
117
+
118
+ it 'should update and return an updated variable' do
119
+ VCR.use_cassette('add FTP environment cassette') do
120
+ @client.create_environment(@e1)
121
+ end
122
+ VCR.use_cassette('update FTP environment cassette') do
123
+ @updated_environment = @client.update_environment(@e2)
124
+ end
125
+
126
+ expect(@updated_environment.settings['providerSettings'][0]['value']['value']).to match('ftp.acme.com')
127
+ end
128
+ end
129
+
130
+ describe 'Delete Environment 12168' do
131
+ before :each do
132
+ @client = AppVeyor::Client.new
133
+ end
134
+
135
+ it 'should be able to delete an environment' do
136
+ expect(@client).to respond_to(:delete_environment)
137
+ end
138
+
139
+ it 'should delete return a 204 response code' do
140
+ VCR.use_cassette('delete environment') do
141
+ @del_env = @client.delete_environment(12168)
142
+ expect(@del_env.status).to match(204)
143
+ end
144
+ end
145
+
146
+ it 'should not have environment 12168 in the environments list' do
147
+ VCR.use_cassette('environment_list_after_delete') do
148
+ expect(@client.find_by_id(12168).deployment_environment_id).to be_nil
149
+ end
150
+ end
151
+
152
+ end
153
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.context AppVeyor::Client do
4
+ describe 'Environments' do
5
+ before(:each) do
6
+ @client = AppVeyor::Client.new
7
+ end
8
+
9
+ it 'should return an environment' do
10
+ VCR.use_cassette('environment cassette') do
11
+ expect(@client.find_by_name('dev')).to be_an_instance_of(AppVeyor::Environment)
12
+ end
13
+ end
14
+
15
+ it 'should return environment 12168' do
16
+ VCR.use_cassette('environment 12168') do
17
+ expect(@client.find_by_id('12168')).to be_an_instance_of(AppVeyor::Environment)
18
+ end
19
+ end
20
+
21
+ it 'should return an environment list' do
22
+ expect(@client).to respond_to(:environment_list)
23
+
24
+ VCR.use_cassette('environment_list cassette') do
25
+ expect(@client.environment_list).to be_a(Hash)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ RSpec.context AppVeyor::Environment do
32
+ describe 'Dev Environment (hits API)' do
33
+ describe 'dev' do
34
+ it 'should have an environment variable' do
35
+ VCR.use_cassette('dev environment cassette') do
36
+ @environment = AppVeyor::Client.new
37
+ @dev_environment = @environment.find_by_name('dev')
38
+
39
+ expect(@dev_environment.settings['environmentVariables'][0]['name'])
40
+ .to match('environment-variable-1')
41
+
42
+ expect(@dev_environment.settings['environmentVariables'][0]['value']['value'])
43
+ .to match('environment-variable')
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.context AppVeyor::Project do
4
+ describe 'Projects Object' do
5
+ before :each do
6
+ @project = AppVeyor::Project.new(
7
+ "projectId"=>253781,
8
+ "accountId"=>33256,
9
+ "accountName"=>"damacus",
10
+ "builds"=>[{"buildId"=>5827807,
11
+ "jobs"=>[],
12
+ "buildNumber"=>17,
13
+ "version"=>"1.0.17",
14
+ "message"=>"Rubocopping",
15
+ "branch"=>"custom_resource",
16
+ "isTag"=>false,
17
+ "commitId"=>"1a5dcedd40582a4ae9e1d39017c0d4ea80e4212d",
18
+ "authorName"=>"Dan Webb",
19
+ "authorUsername"=>"damacus",
20
+ "committerName"=>"Dan Webb",
21
+ "committerUsername"=>"damacus",
22
+ "committed"=>"2016-11-23T23:13:26+00:00",
23
+ "messages"=>[],
24
+ "status"=>"success",
25
+ "started"=>"2016-11-23T23:14:00.0819882+00:00",
26
+ "finished"=>"2016-11-23T23:16:09.0466691+00:00",
27
+ "created"=>"2016-11-23T23:13:53.5210388+00:00",
28
+ "updated"=>"2016-11-23T23:16:09.0466691+00:00"}],
29
+ "name"=>"chef-opsview-client",
30
+ "slug"=>"chef-opsview-client",
31
+ "repositoryType"=>"gitHub",
32
+ "repositoryScm"=>"git",
33
+ "repositoryName"=>"damacus/chef-opsview-client",
34
+ "repositoryBranch"=>"custom_resource",
35
+ "isPrivate"=>false,
36
+ "skipBranchesWithoutAppveyorYml"=>false,
37
+ "enableSecureVariablesInPullRequests"=>false,
38
+ "enableSecureVariablesInPullRequestsFromSameRepo"=>false,
39
+ "enableDeploymentInPullRequests"=>false,
40
+ "rollingBuilds"=>false,
41
+ "alwaysBuildClosedPullRequests"=>false,
42
+ "tags"=>"",
43
+ "nuGetFeed"=>{"id"=>"chef-opsview-client-h4ujwyhcqlss",
44
+ "name"=>"Project chef-opsview-client",
45
+ "publishingEnabled"=>false,
46
+ "created"=>"2016-11-13T14:31:03.3641232+00:00"},
47
+ "securityDescriptor"=>{
48
+ "accessRightDefinitions"=>[
49
+ {"name"=>"View","description"=>"View"},
50
+ {"name"=>"RunBuild","description"=>"Run build"},
51
+ {"name"=>"Update","description"=>"Update settings"},
52
+ {"name"=>"Delete", "description"=>"Delete project"}],
53
+ "roleAces"=>[
54
+ {"roleId"=>53960,
55
+ "name"=>"Administrator",
56
+ "isAdmin"=>true,
57
+ "accessRights"=>[
58
+ {"name"=>"View", "allowed"=>true},
59
+ {"name"=>"RunBuild", "allowed"=>true},
60
+ {"name"=>"Update", "allowed"=>true},
61
+ {"name"=>"Delete", "allowed"=>true}
62
+ ]},
63
+ {"roleId"=>53961,
64
+ "name"=>"User",
65
+ "isAdmin"=>false,
66
+ "accessRights"=>[
67
+ {"name"=>"View"},
68
+ {"name"=>"RunBuild"},
69
+ {"name"=>"Update"},
70
+ {"name"=>"Delete"}
71
+ ]}
72
+ ]},
73
+ "created"=>"2016-11-13T14:31:01.25483+00:00",
74
+ "updated"=>"2016-11-13T14:31:39.8699239+00:00"
75
+ )
76
+ end
77
+
78
+ it 'should return a project' do
79
+ expect(@project).to be_an_instance_of(AppVeyor::Project)
80
+ end
81
+
82
+ it 'should have a project and account Id' do
83
+ expect(@project).to respond_to(:project_name)
84
+ expect(@project).to respond_to(:account_id)
85
+ end
86
+
87
+ it 'should return an array of builds' do
88
+ expect(@project.builds).to be_kind_of(Array)
89
+ expect(@project.builds).to_not be_kind_of(String)
90
+ end
91
+ end
92
+
93
+ describe 'Project' do
94
+ before :each do
95
+ @project = AppVeyor::Client.new
96
+ end
97
+
98
+ it 'should return a Project List' do
99
+ VCR.use_cassette('projects list', :record => :new_episodes) do
100
+ expect(@project).to respond_to(:list_projects)
101
+ expect(@project.list_projects).to be_kind_of(Hash)
102
+ expect(@project.list_projects[223829]).to include('chef-appveyor-ci')
103
+ expect(@project.list_projects[223829]).to_not include('chef-opsview-client')
104
+ expect(@project.list_projects).to include(223829 => 'chef-appveyor-ci')
105
+ expect(@project.list_projects).to_not include(223829 => 'otherstuff')
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://ci.appveyor.com/api/environments
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"deploymentEnvironmentId":12168,"name":"production","provider":"FTP","settings":{"providerSettings":[{"name":"server","value":{"value":"ftp.server.com","isEncrypted":false}},{"name":"username","value":{"value":"ftp-user","isEncrypted":false}},{"name":"password","value":{"value":"password","isEncrypted":true}}],"environmentVariables":[{"name":"my-var","value":{"value":"123","isEncrypted":false}}]}}'
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Authorization:
13
+ - Bearer <APPVEYOR_API_KEY>
14
+ User-Agent:
15
+ - Faraday v0.9.2
16
+ Content-Type:
17
+ - application/json
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Cache-Control:
26
+ - no-cache
27
+ Pragma:
28
+ - no-cache
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Expires:
32
+ - "-1"
33
+ Server:
34
+ - Microsoft-IIS/8.5
35
+ X-Aspnet-Version:
36
+ - 4.0.30319
37
+ X-Powered-By:
38
+ - ASP.NET
39
+ Date:
40
+ - Mon, 28 Nov 2016 14:12:39 GMT
41
+ Content-Length:
42
+ - '1129'
43
+ body:
44
+ encoding: UTF-8
45
+ string: '{"deploymentEnvironmentId":12172,"accountId":33256,"name":"production","provider":"FTP","environmentAccessKey":"qd3tf55evhthpimc","settings":{"providerSettings":[{"name":"server","value":{"isEncrypted":false,"value":"ftp.server.com"}},{"name":"username","value":{"isEncrypted":false,"value":"ftp-user"}},{"name":"password","value":{"isEncrypted":true,"value":"password"}}],"environmentVariables":[{"name":"my-var","value":{"isEncrypted":false,"value":"123"}}],"notifications":[]},"projectsMode":0,"selectedProjects":[],"securityDescriptor":{"accessRightDefinitions":[{"name":"View","description":"View"},{"name":"Deploy","description":"Deploy
46
+ build"},{"name":"Update","description":"Update"},{"name":"Delete","description":"Delete"}],"roleAces":[{"roleId":53960,"name":"Administrator","isAdmin":true,"accessRights":[{"name":"View","allowed":true},{"name":"Deploy","allowed":true},{"name":"Update","allowed":true},{"name":"Delete","allowed":true}]},{"roleId":53961,"name":"User","isAdmin":false,"accessRights":[{"name":"View"},{"name":"Deploy"},{"name":"Update"},{"name":"Delete"}]}]},"created":"2016-11-28T14:12:38.747127+00:00"}'
47
+ http_version:
48
+ recorded_at: Mon, 28 Nov 2016 14:12:40 GMT
49
+ recorded_with: VCR 3.0.3