droneio 1.0.0

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.
@@ -0,0 +1,54 @@
1
+ #
2
+ # Copyright 2016 Drone.io Developers
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require "representable/json"
18
+
19
+ module Drone
20
+ #
21
+ # Transform toplevel JSON payload
22
+ #
23
+ class PayloadRepresenter < Representable::Decorator
24
+ include Representable::JSON
25
+
26
+ # @!attribute repo
27
+ # @return [Drone::Repo] the repo configuration
28
+ property :repo,
29
+ decorator: RepoRepresenter,
30
+ class: Repo
31
+
32
+ # @!attribute system
33
+ # @return [Drone::System] the system configuration
34
+ property :system,
35
+ decorator: SystemRepresenter,
36
+ class: System
37
+
38
+ # @!attribute build
39
+ # @return [Drone::Build] the build configuration
40
+ property :build,
41
+ decorator: BuildRepresenter,
42
+ class: Build
43
+
44
+ # @!attribute workspace
45
+ # @return [Drone::Workspace] the workspace configuration
46
+ property :workspace,
47
+ decorator: WorkspaceRepresenter,
48
+ class: Workspace
49
+
50
+ # @!attribute vargs
51
+ # @return [Hash] the plugin specific payload
52
+ property :vargs
53
+ end
54
+ end
@@ -0,0 +1,87 @@
1
+ #
2
+ # Copyright 2016 Drone.io Developers
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require "virtus"
18
+
19
+ module Drone
20
+ #
21
+ # Represent `repo` JSON as a model
22
+ #
23
+ class Repo
24
+ # Workaround to include virtus without YARD warning
25
+ send :include, Virtus.model
26
+
27
+ # @!attribute id
28
+ # @return [Integer] the ID of the repo
29
+ attribute :id, Integer
30
+
31
+ # @!attribute owner
32
+ # @return [String] the owner name
33
+ attribute :owner, String
34
+
35
+ # @!attribute name
36
+ # @return [String] the repo name
37
+ attribute :name, String
38
+
39
+ # @!attribute full_name
40
+ # @return [String] the full repo name
41
+ attribute :full_name, String
42
+
43
+ # @!attribute avatar
44
+ # @return [String] the URL to the repo avatar
45
+ attribute :avatar, String
46
+
47
+ # @!attribute link
48
+ # @return [String] the URL to the repo website
49
+ attribute :link, String
50
+
51
+ # @!attribute clone
52
+ # @return [String] the URL to the repo SCM system
53
+ attribute :clone, String
54
+
55
+ # @!attribute branch
56
+ # @return [String] the repo default branch
57
+ attribute :branch, String
58
+
59
+ # @!attribute timeout
60
+ # @return [Integer] the timeout value
61
+ attribute :timeout, Integer
62
+
63
+ # @!attribute private
64
+ # @return [Boolean] the flag if repo is private
65
+ attribute :private, Boolean
66
+
67
+ # @!attribute trusted
68
+ # @return [Boolean] the flag if the repo is trusted
69
+ attribute :trusted, Boolean
70
+
71
+ # @!attribute pr
72
+ # @return [Boolean] the flag if pull requests are allowed
73
+ attribute :pr, Boolean
74
+
75
+ # @!attribute push
76
+ # @return [Boolean] the flag if pushs are allowed
77
+ attribute :push, Boolean
78
+
79
+ # @!attribute deploys
80
+ # @return [String] the flag if deploys are allowed
81
+ attribute :deploys, Boolean
82
+
83
+ # @!attribute tags
84
+ # @return [String] the flag if tags are allowed
85
+ attribute :tags, Boolean
86
+ end
87
+ end
@@ -0,0 +1,94 @@
1
+ #
2
+ # Copyright 2016 Drone.io Developers
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require "representable/json"
18
+
19
+ module Drone
20
+ #
21
+ # Transform `repo` JSON payload
22
+ #
23
+ class RepoRepresenter < Representable::Decorator
24
+ include Representable::JSON
25
+
26
+ # @!attribute id
27
+ # @return [Integer] the ID of the repo
28
+ property :id
29
+
30
+ # @!attribute owner
31
+ # @return [String] the owner name
32
+ property :owner
33
+
34
+ # @!attribute name
35
+ # @return [String] the repo name
36
+ property :name
37
+
38
+ # @!attribute full_name
39
+ # @return [String] the full repo name
40
+ property :full_name
41
+
42
+ # @!attribute avatar
43
+ # @return [String] the URL to the repo avatar
44
+ property :avatar,
45
+ as: :avatar_url
46
+
47
+ # @!attribute link
48
+ # @return [String] the URL to the repo website
49
+ property :link,
50
+ as: :link_url
51
+
52
+ # @!attribute clone
53
+ # @return [String] the URL to the repo SCM system
54
+ property :clone,
55
+ as: :clone_url
56
+
57
+ # @!attribute branch
58
+ # @return [String] the repo default branch
59
+ property :branch,
60
+ as: :default_branch
61
+
62
+ # @!attribute timeout
63
+ # @return [Integer] the timeout value
64
+ property :timeout
65
+
66
+ # @!attribute private
67
+ # @return [Boolean] the flag if repo is private
68
+ property :private
69
+
70
+ # @!attribute trusted
71
+ # @return [Boolean] the flag if the repo is trusted
72
+ property :trusted
73
+
74
+ # @!attribute pr
75
+ # @return [Boolean] the flag if pull requests are allowed
76
+ property :pr,
77
+ as: :allow_pr
78
+
79
+ # @!attribute push
80
+ # @return [Boolean] the flag if pushs are allowed
81
+ property :push,
82
+ as: :allow_push
83
+
84
+ # @!attribute deploys
85
+ # @return [String] the flag if deploys are allowed
86
+ property :deploys,
87
+ as: :allow_deploys
88
+
89
+ # @!attribute tags
90
+ # @return [String] the flag if tags are allowed
91
+ property :tags,
92
+ as: :allow_tags
93
+ end
94
+ end
@@ -0,0 +1,47 @@
1
+ #
2
+ # Copyright 2016 Drone.io Developers
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require "virtus"
18
+
19
+ module Drone
20
+ #
21
+ # Represent `system` JSON as a model
22
+ #
23
+ class System
24
+ # Workaround to include virtus without YARD warning
25
+ send :include, Virtus.model
26
+
27
+ # @!attribute version
28
+ # @return [String] the version of the Drone server
29
+ attribute :version, String
30
+
31
+ # @!attribute link
32
+ # @return [String] the link to the Drone server
33
+ attribute :link, String
34
+
35
+ # @!attribute plugins
36
+ # @return [Array] the used plugins within the build
37
+ attribute :plugins, Array[String]
38
+
39
+ # @!attribute privileged
40
+ # @return [Array] the list of privileged plugins
41
+ attribute :privileged, Array[String]
42
+
43
+ # @!attribute globals
44
+ # @return [Array] the used global environment vars
45
+ attribute :globals, Array[String]
46
+ end
47
+ end
@@ -0,0 +1,48 @@
1
+ #
2
+ # Copyright 2016 Drone.io Developers
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require "representable/json"
18
+
19
+ module Drone
20
+ #
21
+ # Transform `system` JSON payload
22
+ #
23
+ class SystemRepresenter < Representable::Decorator
24
+ include Representable::JSON
25
+
26
+ # @!attribute version
27
+ # @return [String] the version of the Drone server
28
+ property :version
29
+
30
+ # @!attribute link
31
+ # @return [String] the link to the Drone server
32
+ property :link,
33
+ as: :link_url
34
+
35
+ # @!attribute plugins
36
+ # @return [Array] the used plugins within the build
37
+ collection :plugins
38
+
39
+ # @!attribute privileged
40
+ # @return [Array] the list of privileged plugins
41
+ collection :privileged,
42
+ as: :privileged_plugins
43
+
44
+ # @!attribute globals
45
+ # @return [Array] the used global environment vars
46
+ collection :globals
47
+ end
48
+ end
@@ -0,0 +1,43 @@
1
+ #
2
+ # Copyright 2016 Drone.io Developers
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require "virtus"
18
+
19
+ module Drone
20
+ #
21
+ # Represent `workspace` JSON as a model
22
+ #
23
+ class Workspace
24
+ # Workaround to include virtus without YARD warning
25
+ send :include, Virtus.model
26
+
27
+ # @!attribute root
28
+ # @return [String] the root path of the workspace
29
+ attribute :root, String
30
+
31
+ # @!attribute path
32
+ # @return [String] the absolute path to the source
33
+ attribute :path, String
34
+
35
+ # @!attribute netrc
36
+ # @return [Drone::Netrc] the netrc configuration
37
+ attribute :netrc, Netrc
38
+
39
+ # @!attribute keys
40
+ # @return [Drone::Key] the key configuration
41
+ attribute :keys, Key
42
+ end
43
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ # Copyright 2016 Drone.io Developers
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require "representable/json"
18
+
19
+ module Drone
20
+ #
21
+ # Transform `workspace` JSON payload
22
+ #
23
+ class WorkspaceRepresenter < Representable::Decorator
24
+ include Representable::JSON
25
+
26
+ # @!attribute root
27
+ # @return [String] the root path of the workspace
28
+ property :root
29
+
30
+ # @!attribute path
31
+ # @return [String] the absolute path to the source
32
+ property :path
33
+
34
+ # @!attribute netrc
35
+ # @return [Drone::Netrc] the netrc configuration
36
+ property :netrc,
37
+ decorator: NetrcRepresenter,
38
+ class: Netrc
39
+
40
+ # @!attribute keys
41
+ # @return [Drone::Key] the key configuration
42
+ property :keys,
43
+ decorator: KeyRepresenter,
44
+ class: Key
45
+ end
46
+ end
@@ -0,0 +1,55 @@
1
+ #
2
+ # Copyright 2016 Drone.io Developers
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require "json"
18
+
19
+ module Drone
20
+ #
21
+ # Plugin payload parser for Drone
22
+ #
23
+ class Plugin
24
+ attr_accessor :input
25
+ attr_accessor :result
26
+
27
+ # Initialize the plugin parser
28
+ #
29
+ # @param input [String] the JSON as a string to parse
30
+ # @return [Drone::Plugin] the instance of that class
31
+ def initialize(input)
32
+ self.input = input
33
+
34
+ yield(
35
+ parse
36
+ ) if block_given?
37
+ end
38
+
39
+ # Parse the provided payload
40
+ #
41
+ # @return [Drone::Payload] the parsed payload within model
42
+ # @raise [Drone::InvalidJsonError] if the provided JSON is invalid
43
+ def parse
44
+ self.result ||= Payload.new.tap do |payload|
45
+ PayloadRepresenter.new(
46
+ payload
47
+ ).from_json(
48
+ input
49
+ )
50
+ end
51
+ rescue MultiJson::ParseError
52
+ raise InvalidJsonError
53
+ end
54
+ end
55
+ end