appveyor-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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
+ [![CircleCI](https://circleci.com/gh/damacus/appveyor-api/tree/master.svg?style=svg)](https://circleci.com/gh/damacus/appveyor-api/tree/master)
2
+
3
+ # appveyor-api
4
+ A wrapper for the AppVeyor API
5
+
6
+ Inspiration from https://github.com/esaio/esa-ruby
7
+
8
+ # Example Usage
9
+ This client will accept either an `APPVEYOR_API_KEY` as an argument or detect an environment variable
10
+
11
+ ### Environment Variable
12
+ `$APPVEYOR_API_KEY`
13
+
14
+ ### Access_token
15
+ `@client = AppVeyor::Client.new(access_token:'123456787980nthrthrt)`
16
+
17
+ ## List Environments
18
+ `@client.list_environments`
19
+
20
+ ## List Projects
21
+ `@client.list_projects`
22
+
23
+ ## Update Environment
24
+ `awesome_environment={"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}}]}}`
25
+
26
+ `@client.create_environment(awesome_environment)`
@@ -0,0 +1,37 @@
1
+
2
+ # coding: utf-8
3
+ # frozen_string_literal: true
4
+ lib = File.expand_path('../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'appveyor-api'
9
+ spec.version = '0.0.1'
10
+ spec.authors = ['Dan Webb']
11
+ spec.email = ['dan.webb@damacus.io']
12
+ spec.summary = 'Gem to wrap AppVeyor API'
13
+ spec.description = 'Gem to wrap AppVeyor API for simpler interactions with the AppVeyor Api'
14
+ spec.homepage = 'https://github.com/damacus/appveyor-api'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~>1.12'
23
+ spec.add_development_dependency 'rake', '~> 11.3'
24
+ spec.add_development_dependency 'vcr', '~> 3.0'
25
+ spec.add_development_dependency 'webmock', '~> 2.1'
26
+ spec.add_development_dependency 'rb-readline', '~> 0.5'
27
+ spec.add_development_dependency 'growl', '~> 1.0'
28
+ spec.add_development_dependency 'guard', '~> 2.14'
29
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
30
+ spec.add_development_dependency 'rspec', '~> 3.5'
31
+ spec.add_development_dependency 'simplecov', '~> 0.12'
32
+ spec.add_development_dependency 'rspec_junit_formatter', '~> 0.2'
33
+
34
+ spec.add_dependency 'faraday', '~> 0.9.2'
35
+ spec.add_dependency 'faraday_middleware', '~> 0.10.0'
36
+ spec.add_dependency 'json', '~> 2.0'
37
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'faraday_middleware'
5
+
6
+ require 'appveyor-api/client'
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+ # Build
3
+ def start_build
4
+ # {
5
+ # accountName: 'your-account-name',
6
+ # projectSlug: 'project-slug-from-url',
7
+ # branch: 'master',
8
+ # environmentVariables: {
9
+ # my_var: 'value',
10
+ # another_var: 'another value'
11
+ # }
12
+ # }
13
+ end
14
+
15
+ def start_commit_build
16
+ # {
17
+ # accountName: 'your-account-name',
18
+ # projectSlug: 'project-slug-from-url',
19
+ # branch: 'develop',
20
+ # commitId: '3e9d9468'
21
+ # }
22
+ end
23
+
24
+ def start_pull_request_build
25
+ # {
26
+ # accountName: 'your-account-name',
27
+ # projectSlug: 'project-slug-from-url',
28
+ # pullRequestId: 3
29
+ # }
30
+ end
31
+
32
+ def cancel_build
33
+ # DELETE /api/builds/{accountName}/{projectSlug}/{buildVersion}
34
+ end
@@ -0,0 +1,78 @@
1
+
2
+ # frozen_string_literal: true
3
+ require 'appveyor-api/environments'
4
+ require 'appveyor-api/projects'
5
+ require 'appveyor-api/response'
6
+
7
+ module AppVeyor
8
+ # Main client object that you interactive with AppVeyor via
9
+ #
10
+ # == Parameters:
11
+ #
12
+ # == Use:
13
+ # @client = AppVeyor::Client.new
14
+ # @client.find_by_name('dev')
15
+ #
16
+ class Client
17
+ include Environments
18
+ include Projects
19
+
20
+ def initialize(access_token: nil)
21
+ @access_token = access_token
22
+ end
23
+
24
+ def send_get(path, params = nil, headers = nil)
25
+ send_request(:get, path, params, headers)
26
+ end
27
+
28
+ def send_post(path, params = nil, headers = nil)
29
+ send_request(:post, path, params, headers)
30
+ end
31
+
32
+ def send_put(path, params = nil, headers = nil)
33
+ send_request(:put, path, params, headers)
34
+ end
35
+
36
+ def send_delete(path, params = nil, headers = nil)
37
+ send_request(:delete, path, params, headers)
38
+ end
39
+
40
+ def send_request(method, path, params = nil, headers = nil)
41
+ AppVeyor::Response.new(appveyor_connection.send(method, path, params, headers))
42
+ end
43
+
44
+ def appveyor_connection
45
+ @appveyor_connection ||= Faraday.new(faraday_options) do |c|
46
+ c.request :json
47
+ c.response :json
48
+ c.adapter Faraday.default_adapter
49
+ end
50
+ end
51
+
52
+ def faraday_options
53
+ {
54
+ url: faraday_url,
55
+ headers: faraday_headers
56
+ }
57
+ end
58
+
59
+ def default_headers
60
+ {
61
+ 'Accept' => 'application/json',
62
+ 'Authorization' => "Bearer #{access_token}"
63
+ }
64
+ end
65
+
66
+ def faraday_headers
67
+ default_headers
68
+ end
69
+
70
+ def access_token
71
+ @access_token || ENV['APPVEYOR_API_KEY']
72
+ end
73
+
74
+ def faraday_url
75
+ @api_endpoint ||= 'https://ci.appveyor.com'
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ # Collaborators
3
+
4
+ def get_collaborators(config)
5
+ # HTTParty.get('https://ci.appveyor.com/api/collaborators',
6
+ # headers: { 'Authorization' => "Bearer #{config.api_token}" })
7
+ end
8
+
9
+ def get_collaborator(config, _user_id)
10
+ # HTTParty.get("https://ci.appveyor.com/api/collaborator/#{userId}",
11
+ # headers: { 'Authorization' => "Bearer #{config.api_token}" })
12
+ end
13
+
14
+ def add_collaborator
15
+ end
16
+
17
+ def update_collaborator
18
+ end
19
+
20
+ def delete_collaborator
21
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+ # Deployment
3
+ def get_deployment(_config, _deployment_id)
4
+ end
5
+
6
+ def start_deployment(config)
7
+ # body = {
8
+ # environmentName: 'psm-archive-production',
9
+ # accountName: 'js-devops',
10
+ # projectSlug: 'psm-archive',
11
+ # buildVersion: '1.0.269'
12
+ # }
13
+ # response = HTTParty.post('https://ci.appveyor.com/api/deployments',
14
+ # body: body.to_json,
15
+ # headers: { 'Authorization' => "Bearer #{config.api_token}",
16
+ # 'Content-Type' => 'application/json',
17
+ # 'Accept' => 'application/json' })
18
+ #
19
+ # puts response.code
20
+ end
21
+
22
+ # def start_deployment(config)
23
+ # conn = Faraday.new(:url => 'http://sushi.com') do |faraday|
24
+ # faraday.request :url_encoded # form-encode POST params
25
+ # faraday.response :logger # log requests to STDOUT
26
+ # faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
27
+ # end
28
+ # end
29
+
30
+ def start_deploy(api_token)
31
+ # body = {
32
+ # environmentName: environment_name,
33
+ # accountName: account_name,
34
+ # projectSlug: project_slug,
35
+ # buildVersion: build_version
36
+ # }
37
+ # response = HTTParty.post('https://ci.appveyor.com/api/deployments',
38
+ # body: body.to_json,
39
+ # headers: { 'Authorization' => "Bearer #{api_token}",
40
+ # 'Content-Type' => 'application/json',
41
+ # 'Accept' => 'application/json'
42
+ # })
43
+ end
44
+
45
+ def cancel_deployment(_config, _deployment_id)
46
+ # /api/deployments/stop
47
+ end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+ require 'faraday'
3
+ require 'json'
4
+
5
+ # Wrapper around the Environment object
6
+ # Used for searching for environments
7
+ #
8
+ # == Parameters:
9
+ # name
10
+ # A String containing the environment you are looking for
11
+ #
12
+ # == Returns:
13
+ # An environment
14
+ #
15
+ module AppVeyor
16
+ #
17
+ #
18
+ module Environments
19
+ # returns Environments hash
20
+ def environment_list
21
+ envs_list = send_get('/api/environments').body
22
+ envs_hash = {}
23
+ (0..envs_list.length - 1).each do |e|
24
+ envs_hash.store(envs_list[e]['deploymentEnvironmentId'], envs_list[e]['name'])
25
+ end
26
+ envs_hash
27
+ end
28
+
29
+ def find_by_name(name)
30
+ found_environment = {}
31
+ found_environment = environment_list.select { |key, val| val == name }
32
+ raise 'Multiple Environments found during search' if found_environment.length > 1
33
+
34
+ environment = send_get("/api/environments/#{found_environment.keys.first}/settings")
35
+ AppVeyor::Environment.new(environment.body['environment'])
36
+ end
37
+
38
+ def find_by_id(id)
39
+ environment = send_get("/api/environments/#{id}/settings")
40
+ AppVeyor::Environment.new(environment.body['environment'])
41
+ end
42
+
43
+ def create_environment(environment)
44
+ env = send_post('/api/environments', environment)
45
+ AppVeyor::Environment.new(env.body['environment'])
46
+ end
47
+
48
+ def update_environment(environment)
49
+ env = send_put('/api/environments', environment)
50
+ AppVeyor::Environment.new(env.body)
51
+ end
52
+
53
+ def delete_environment(environment_id)
54
+ send_delete("/api/environments/#{environment_id}")
55
+ end
56
+ end
57
+ end
58
+ # The environment object as per the AppVeyor API documentation
59
+ # https://www.appveyor.com/docs/api/environments-deployments/
60
+ # CRUD actions for an environment
61
+ #
62
+ # == Parameters:
63
+ # deployment_environment_id:
64
+ # projects_mode:
65
+ # account_id
66
+ # name:
67
+ # settings
68
+ # => provider_settings: array of settings
69
+ # [{"name"=>"test_setting",
70
+ # "value"=>{"isEncrypted"=>false,
71
+ # "value"=>"myaccount"}}]
72
+
73
+ module AppVeyor
74
+ # == Returns:
75
+ # An environment object
76
+ #
77
+ class Environment
78
+ def initialize(options = {})
79
+ options.each { |k, v| public_send("#{k}=", v) } if options
80
+ end
81
+
82
+ def id
83
+ @deploymentEnvironmentId
84
+ end
85
+
86
+ def deployment_environment_id
87
+ @deploymentEnvironmentId
88
+ end
89
+
90
+ def account_id
91
+ @accountId
92
+ end
93
+
94
+ def projects_mode
95
+ @projectsMode
96
+ end
97
+
98
+ def selected_projects
99
+ @selectedProjects
100
+ end
101
+
102
+ attr_accessor :deploymentEnvironmentId
103
+ attr_accessor :accountId
104
+ attr_accessor :name
105
+ attr_accessor :provider
106
+ attr_accessor :projectsMode
107
+ attr_accessor :created
108
+ attr_accessor :updated
109
+ attr_accessor :settings
110
+ attr_accessor :provider_settings
111
+ attr_accessor :environmentAccessKey
112
+ attr_accessor :selectedProjects
113
+ attr_accessor :projects
114
+ attr_accessor :securityDescriptor
115
+ end
116
+ end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AppVeyor
4
+ module Projects
5
+ def get_project_last_build(config)
6
+ # response = HTTParty.get("https://ci.appveyor.com/api/projects/#{config.account}/#{config.project}",
7
+ # headers: { 'Authorization' => "Bearer #{config.api_token}" })
8
+ # response['build']['message']
9
+ end
10
+
11
+ def list_projects()
12
+ projects_list = send_get('/api/projects').body
13
+ projects_hash = {}
14
+ (0..projects_list.length - 1).each do |x|
15
+ projects_hash.store(projects_list[x]['projectId'], projects_list[x]['name'])
16
+ end
17
+ projects_hash
18
+ end
19
+ end
20
+
21
+ class Project
22
+ def initialize(options = {})
23
+ options.each { |k, v| public_send("#{k}=", v) } if options
24
+ end
25
+ attr_accessor :projectId
26
+ attr_accessor :accountId
27
+ attr_accessor :accountName
28
+ attr_accessor :builds
29
+ attr_accessor :name
30
+ attr_accessor :slug
31
+ attr_accessor :repositoryType
32
+ attr_accessor :repositoryScm
33
+ attr_accessor :repositoryName
34
+ attr_accessor :repositoryBranch
35
+ attr_accessor :isPrivate
36
+ attr_accessor :skipBranchesWithoutAppveyorYml
37
+ attr_accessor :enableSecureVariablesInPullRequests
38
+ attr_accessor :enableSecureVariablesInPullRequestsFromSameRepo
39
+ attr_accessor :enableDeploymentInPullRequests
40
+ attr_accessor :rollingBuilds
41
+ attr_accessor :alwaysBuildClosedPullRequests
42
+ attr_accessor :tags
43
+ attr_accessor :nuGetFeed
44
+ attr_accessor :securityDescriptor
45
+ attr_accessor :created
46
+ attr_accessor :updated
47
+
48
+ def project_id
49
+ @projectId
50
+ end
51
+
52
+ def account_id
53
+ @accountId
54
+ end
55
+
56
+ def project_name
57
+ @name
58
+ end
59
+
60
+ def account_name
61
+ @accountName
62
+ end
63
+
64
+ def repository_type
65
+ @repositoryType
66
+ end
67
+
68
+ def repository_scm
69
+ @repositoryScm
70
+ end
71
+
72
+ def repository_name
73
+ @repositoryName
74
+ end
75
+
76
+ def repository_branch
77
+ @repositoryBranch
78
+ end
79
+
80
+ def isPrivate
81
+ @isPrivate
82
+ end
83
+
84
+ def skip_branches_without_appveyor_yml
85
+ @skipBranchesWithoutAppveyorYml
86
+ end
87
+
88
+ def enable_secure_variables_in_pull_requests
89
+ @enableSecureVariablesInPullRequests
90
+ end
91
+
92
+ def enable_secure_variables_in_pull_requests_from_same_repo
93
+ @enableSecureVariablesInPullRequestsFromSameRepo
94
+ end
95
+
96
+ def enbale_deployment_in_pull_requests
97
+ @enableDeploymentInPullRequests
98
+ end
99
+
100
+ def rolling_builds
101
+ @rollingBuilds
102
+ end
103
+
104
+ def always_build_closed_pull_requests
105
+ @alwaysBuildClosedPullRequests
106
+ end
107
+
108
+ def nuget_feed
109
+ @nuGetFeed
110
+ end
111
+
112
+ def security_descriptor
113
+ @securityDescriptor
114
+ end
115
+ end
116
+ end