Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3769108
D596.id1449.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D596.id1449.diff
View Options
diff --git a/src/Build/Payloads/AllBuildPayload.php b/src/Build/Payloads/AllBuildPayload.php
new file mode 100644
--- /dev/null
+++ b/src/Build/Payloads/AllBuildPayload.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace Keruald\DockerHub\Build\Payloads;
+
+/**
+ * Represents a build trigger payload to build all branches/tags.
+ */
+class AllBuildPayload extends BuildPayload {
+
+ /**
+ * @var bool
+ */
+ public $build = true;
+
+}
diff --git a/src/Build/Payloads/BuildPayload.php b/src/Build/Payloads/BuildPayload.php
new file mode 100644
--- /dev/null
+++ b/src/Build/Payloads/BuildPayload.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Keruald\DockerHub\Build\Payloads;
+
+/**
+ * Represents a build trigger payload.
+ */
+abstract class BuildPayload {
+
+}
diff --git a/src/Build/Payloads/DockerTagBuildPayload.php b/src/Build/Payloads/DockerTagBuildPayload.php
new file mode 100644
--- /dev/null
+++ b/src/Build/Payloads/DockerTagBuildPayload.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace Keruald\DockerHub\Build\Payloads;
+
+/**
+ * Represents a build trigger payload to build a specific Docker tag.
+ */
+class DockerTagBuildPayload extends BuildPayload {
+
+ /**
+ * @var string
+ */
+ public $docker_tag;
+
+ /**
+ * Initializes a new instance of the DockerTagBuildPayload class.
+ *
+ * @param string $tag The name of the Docker tag to build
+ */
+ public function __construct ($tag) {
+ $this->docker_tag = $tag;
+ }
+
+}
diff --git a/src/Build/Payloads/SourceRepositoryBranchBuildPayload.php b/src/Build/Payloads/SourceRepositoryBranchBuildPayload.php
new file mode 100644
--- /dev/null
+++ b/src/Build/Payloads/SourceRepositoryBranchBuildPayload.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Keruald\DockerHub\Build\Payloads;
+
+/**
+ * Represents a build trigger payload to build a specific repo branch.
+ */
+class SourceRepositoryBranchBuildPayload extends SourceRepositoryBuildPayload {
+
+ /**
+ * Initializes a new instance of the SourceRepositoryBranchBuildPayload class.
+ *
+ * @param string $tag The name of the repo branch to build
+ */
+ public function __construct ($branch) {
+ parent::__construct(SourceRepositoryType::BRANCH, $branch);
+ }
+
+}
diff --git a/src/Build/Payloads/SourceRepositoryBuildPayload.php b/src/Build/Payloads/SourceRepositoryBuildPayload.php
new file mode 100644
--- /dev/null
+++ b/src/Build/Payloads/SourceRepositoryBuildPayload.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace Keruald\DockerHub\Build\Payloads;
+
+/**
+ * Represents a build trigger payload to build a specific tag or branch
+ * from the source repository.
+ */
+abstract class SourceRepositoryBuildPayload extends BuildPayload {
+
+ /**
+ * @var string
+ */
+ public $source_type;
+
+ /**
+ * @var string
+ */
+ public $source_name;
+
+ /**
+ * Initializes a new instance of the SourceRepositoryBuildPayload class.
+ *
+ * @param string $type "Tag" or "Branch"
+ * @param string $name The name of the tag or branch in the repository
+ */
+ public function __construct ($type, $name) {
+ if (!$this->isValidType($type)) {
+ throw new \InvalidArgumentException("Unexpected type: $type.");
+ }
+
+ $this->source_type = $type;
+ $this->source_name = $name;
+ }
+
+ ///
+ /// Helper methods
+ ///
+
+ /**
+ * Determines if type is "Tag" or "Branch".
+ *
+ * @param string $type
+ * @return bool
+ */
+ public function isValidType ($type) {
+ return $type === SourceRepositoryType::TAG
+ || $type === SourceRepositoryType::BRANCH;
+ }
+
+}
diff --git a/src/Build/Payloads/SourceRepositoryTagBuildPayload.php b/src/Build/Payloads/SourceRepositoryTagBuildPayload.php
new file mode 100644
--- /dev/null
+++ b/src/Build/Payloads/SourceRepositoryTagBuildPayload.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Keruald\DockerHub\Build\Payloads;
+
+/**
+ * Represents a build trigger payload to build a specific repo tag.
+ */
+class SourceRepositoryTagBuildPayload extends SourceRepositoryBuildPayload {
+
+ /**
+ * Initializes a new instance of the SourceRepositoryTagBuildPayload class.
+ *
+ * @param string $tag The name of the repo tag to build
+ */
+ public function __construct ($tag) {
+ parent::__construct(SourceRepositoryType::TAG, $tag);
+ }
+
+}
diff --git a/src/Build/Payloads/SourceRepositoryType.php b/src/Build/Payloads/SourceRepositoryType.php
new file mode 100644
--- /dev/null
+++ b/src/Build/Payloads/SourceRepositoryType.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace Keruald\DockerHub\Build\Payloads;
+
+/**
+ * Represents types related to kind of objects existing in a repository.
+ */
+class SourceRepositoryType {
+
+ /**
+ * @const string
+ */
+ const BRANCH = "Branch";
+
+ /**
+ * @const string
+ */
+ const TAG = "Tag";
+
+}
diff --git a/src/Build/TriggerBuild.php b/src/Build/TriggerBuild.php
--- a/src/Build/TriggerBuild.php
+++ b/src/Build/TriggerBuild.php
@@ -4,6 +4,11 @@
use Keruald\DockerHub\DockerHubImage as Image;
+use Keruald\DockerHub\Build\Payloads\AllBuildPayload;
+use Keruald\DockerHub\Build\Payloads\DockerTagBuildPayload;
+use Keruald\DockerHub\Build\Payloads\SourceRepositoryBranchBuildPayload;
+use Keruald\DockerHub\Build\Payloads\SourceRepositoryTagBuildPayload;
+
/**
* this classe represents a trigger for a new build on the Docker Hub registry.
*/
@@ -56,4 +61,44 @@
. '/trigger/' . $this->token . '/';
}
+ ///
+ /// Payloads to specify what to build
+ ///
+
+ /**
+ * Gets a payload to build all branch/tag.
+ *
+ * @return Keruald\DockerHub\Build\Payloads\AllBuildPayload
+ */
+ public function getPayloadForAll () {
+ return new AllBuildPayload;
+ }
+
+ /**
+ * Gets a payload to build the specified Docker tag
+ *
+ * @return Keruald\DockerHub\Build\Payloads\DockerTagBuildPayload
+ */
+ public function getPayloadForDockerTag ($tag) {
+ return new DockerTagBuildPayload($tag);
+ }
+
+ /**
+ * Gets a payload to build the specified repository branch
+ *
+ * @return Keruald\DockerHub\Build\Payloads\SourceRepositoryBranchBuildPayload
+ */
+ public function getPayloadForSourceRepositoryBranch ($branch) {
+ return new SourceRepositoryBranchBuildPayload($branch);
+ }
+
+ /**
+ * Gets a payload to build the specified repository tag
+ *
+ * @return Keruald\DockerHub\Build\Payloads\SourceRepositoryTagBuildPayload
+ */
+ public function getPayloadForSourceRepositoryTag ($tag) {
+ return new SourceRepositoryTagBuildPayload($tag);
+ }
+
}
diff --git a/tests/Build/TriggerBuildTest.php b/tests/Build/TriggerBuildTest.php
--- a/tests/Build/TriggerBuildTest.php
+++ b/tests/Build/TriggerBuildTest.php
@@ -4,6 +4,9 @@
use Keruald\DockerHub\DockerHubImage;
use Keruald\DockerHub\Build\TriggerBuild;
+use Keruald\DockerHub\Build\Payloads\AllBuildPayload;
+use Keruald\DockerHub\Build\Payloads\DockerTagBuildPayload;
+use Keruald\DockerHub\Build\Payloads\SourceRepositoryBuildPayload;
class TriggerBuildTest extends \PHPUnit_Framework_TestCase {
@@ -24,4 +27,34 @@
);
}
+ public function testGetPayloadForAll () {
+ // {"build": true}
+ $payload = $this->trigger->getPayloadForAll();
+ $this->assertInstanceOf(AllBuildPayload::class, $payload);
+ $this->assertTrue($payload->build);
+ }
+
+ public function testGetPayloadForDockerTag () {
+ // {"docker_tag": "master"}
+ $payload = $this->trigger->getPayloadForDockerTag("master");
+ $this->assertInstanceOf(DockerTagBuildPayload::class, $payload);
+ $this->assertSame($payload->docker_tag, "master");
+ }
+
+ public function testGetPayloadForSourceRepositoryBranch () {
+ // {"source_type": "Branch", "source_name": "staging"}
+ $payload = $this->trigger->getPayloadForSourceRepositoryBranch("staging");
+ $this->assertInstanceOf(SourceRepositoryBuildPayload::class, $payload);
+ $this->assertSame($payload->source_type, "Branch");
+ $this->assertSame($payload->source_name, "staging");
+ }
+
+ public function testGetPayloadForSourceRepositoryTag () {
+ // {"source_type": "Tag", "source_name": "v1.1"}
+ $payload = $this->trigger->getPayloadForSourceRepositoryTag("v1.1");
+ $this->assertInstanceOf(SourceRepositoryBuildPayload::class, $payload);
+ $this->assertSame($payload->source_type, "Tag");
+ $this->assertSame($payload->source_name, "v1.1");
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 13:01 (10 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2260199
Default Alt Text
D596.id1449.diff (8 KB)
Attached To
Mode
D596: Add support for build trigger payloads
Attached
Detach File
Event Timeline
Log In to Comment