Skip to content

Commit 0abf8af

Browse files
committed
Add projects
Update README
1 parent 8e745e9 commit 0abf8af

File tree

8 files changed

+608
-32
lines changed

8 files changed

+608
-32
lines changed

Gemfile.lock

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ PATH
22
remote: .
33
specs:
44
appveyor-api (0.0.1)
5-
faraday
6-
faraday_middleware
7-
json
5+
faraday (~> 0.9.2)
6+
faraday_middleware (~> 0.10.0)
7+
json (~> 2.0)
88

99
GEM
1010
remote: https://rubygems.org/
@@ -96,17 +96,17 @@ PLATFORMS
9696

9797
DEPENDENCIES
9898
appveyor-api!
99-
bundler
100-
growl
101-
guard
102-
guard-rspec
103-
rake
104-
rb-readline
105-
rspec
106-
rspec_junit_formatter
107-
simplecov
108-
vcr
109-
webmock
99+
bundler (~> 1.12)
100+
growl (~> 1.0)
101+
guard (~> 2.14)
102+
guard-rspec (~> 4.7)
103+
rake (~> 11.3)
104+
rb-readline (~> 0.5)
105+
rspec (~> 3.5)
106+
rspec_junit_formatter (~> 0.2)
107+
simplecov (~> 0.12)
108+
vcr (~> 3.0)
109+
webmock (~> 2.1)
110110

111111
BUNDLED WITH
112112
1.12.5

README.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,24 @@
33
# appveyor-api
44
A wrapper for the AppVeyor API
55

6-
Inspiration from
7-
https://github.com/esaio/esa-ruby
6+
Inspiration from https://github.com/esaio/esa-ruby
87

9-
# Usage
10-
Environment Variable $APPVEYOR_API_KEY
11-
@client = AppVeyor::Client.new(access_token:'<insert_your_api_key_here')
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)`

lib/appveyor-api/client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
# frozen_string_literal: true
33
require 'appveyor-api/environments'
4+
require 'appveyor-api/projects'
45
require 'appveyor-api/response'
56

67
module AppVeyor
@@ -14,6 +15,7 @@ module AppVeyor
1415
#
1516
class Client
1617
include Environments
18+
include Projects
1719

1820
def initialize(access_token: nil)
1921
@access_token = access_token

lib/appveyor-api/projects.rb

Lines changed: 113 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,116 @@
11
# frozen_string_literal: true
2-
# Project
3-
def get_project_last_build(config)
4-
# response = HTTParty.get("https://ci.appveyor.com/api/projects/#{config.account}/#{config.project}",
5-
# headers: { 'Authorization' => "Bearer #{config.api_token}" })
6-
# response['build']['message']
7-
end
82

9-
def get_projects(config)
10-
# response = Faraday.get do |req|
11-
# req.url "https://ci.appveyor.com/api/projects/#{config.account}/#{config.project}"
12-
# req.headers['Authorization'] = "Bearer #{config.api_token}"
13-
# end
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
14116
end

spec/appveyor-api/project_spec.rb

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

spec/cassettes/project_list.yml

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)