Skip to content

Commit 5c74b38

Browse files
bryonbeanzackgalbreath
authored andcommitted
feat: adds set status pending to workflow
1 parent cddb2cd commit 5c74b38

File tree

5 files changed

+124
-5
lines changed

5 files changed

+124
-5
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set(CLIENT_TEST_SCRIPT1 CACHE FILEPATH "Path to client management test script")
2121
set(CLIENT_TEST_SCRIPT2 CACHE FILEPATH "Path to client management test script")
2222
set(CDASH_GITHUB_USERNAME "" CACHE STRING "Github user for testing")
2323
set(CDASH_GITHUB_PASSWORD "" CACHE STRING "Github user's password")
24+
set(CDASH_GITHUB_API_TOKEN "" CACHE STRING "Github token to perform GitHub API procedures")
2425

2526
get_filename_component(CDASH_DIR_NAME_DEFAULT ${CDash_SOURCE_DIR} NAME)
2627
set(CDASH_DIR_NAME "${CDASH_DIR_NAME_DEFAULT}" CACHE STRING "URL suffix. Ie 'http://<CDASH_SERVER>/<CDASH_DIR_NAME>'")
@@ -156,6 +157,7 @@ $CDASH_DB_NAME = 'cdash4simpletest';
156157
$CDASH_TESTING_MODE = true;
157158
$CDASH_REGISTRATION_EMAIL_VERIFY = false;
158159
$CDASH_TESTING_RENAME_LOGS = ${rename_logs};
160+
$CDASH_GITHUB_API_TOKEN = '${CDASH_GITHUB_API_TOKEN}';
159161
$CDASH_DB_HOST = '${CDASH_DB_HOST}';
160162
$CDASH_DB_LOGIN = '${CDASH_DB_LOGIN}';
161163
$CDASH_DB_PORT = '${CDASH_DB_PORT}';

app/Model/Repository.php

+39
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
namespace CDash\Model;
1616

17+
use CDash\Config;
18+
use CDash\Lib\Repository\GitHub;
19+
use CDash\Log;
20+
1721
class Repository
1822
{
1923
const CVS = 0;
@@ -51,4 +55,39 @@ public static function getViewers()
5155
}
5256
return $viewers;
5357
}
58+
59+
public static function factory(Project $project)
60+
{
61+
switch ($project->CvsViewerType)
62+
{
63+
case self::VIEWER_GITHUB:
64+
list($owner, $repo) = array_values(
65+
Repository::getGitHubRepoInformationFromUrl($project->CvsUrl)
66+
);
67+
$token = Config::getInstance()->get('CDASH_GITHUB_API_TOKEN');
68+
$service = new GitHub($token, $owner, $repo);
69+
break;
70+
default:
71+
$vcs = $project->CvsViewerType ?: 'none';
72+
$e = new \Exception("Unknown CvsViewerType [{$vcs}]");
73+
Log::getInstance()->error($e);
74+
}
75+
return $service;
76+
}
77+
78+
protected static function getGitHubRepoInformationFromUrl($url)
79+
{
80+
$url = str_replace('//', '', $url);
81+
$parts = explode('/', $url);
82+
$info = ['owner' => null, 'repo' => null];
83+
if (isset($parts[1])) {
84+
$info['owner'] = $parts[1];
85+
}
86+
87+
if (isset($parts[2])) {
88+
$info['repo'] = $parts[2];
89+
}
90+
91+
return $info;
92+
}
5493
}

include/CDash/ServiceContainer.php

+13
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,17 @@ public function setContainer(Container $container)
7474
{
7575
$this->container = $container;
7676
}
77+
78+
public static function singleton($class_name)
79+
{
80+
/** @var ServiceContainer $self */
81+
$self = self::getInstance();
82+
return $self->get($class_name);
83+
}
84+
85+
public static function instance($class_name)
86+
{
87+
$self = self::getInstance();
88+
return $self->create($class_name);
89+
}
7790
}

include/do_submit.php

+20-5
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
=========================================================================*/
1616

1717
//error_reporting(0); // disable error reporting
18-
use Bernard\Message\PlainMessage;
19-
use Bernard\Producer;
20-
use Bernard\QueueFactory\PersistentFactory;
21-
use Bernard\Serializer;
2218
use CDash\Config;
2319
use CDash\Middleware\Queue;
2420
use CDash\Middleware\Queue\DriverFactory as QueueDriverFactory;
@@ -28,9 +24,12 @@
2824
use CDash\Model\BuildFile;
2925
use CDash\Model\PendingSubmissions;
3026
use CDash\Model\Project;
27+
use CDash\Model\Repository;
3128
use CDash\Model\Site;
29+
use CDash\Service\RepositoryService;
30+
use CDash\ServiceContainer;
31+
use GuzzleHttp\Client as HttpClient;
3232
use Ramsey\Uuid\Uuid;
33-
use Symfony\Component\EventDispatcher\EventDispatcher;
3433

3534
require_once 'include/ctestparser.php';
3635
include_once 'include/common.php';
@@ -175,9 +174,25 @@ function do_submit($fileHandleOrSubmissionId, $projectid, $buildid = null,
175174

176175
// Send the emails if necessary
177176
if ($handler instanceof UpdateHandler) {
177+
// TODO: set repository status pending here
178+
$builds = $handler->getBuilds();
179+
180+
/** @var Build $build */
181+
$build = array_pop($builds);
182+
$project = new Project();
183+
$project->Id = $build->ProjectId;
184+
$project->Fill();
185+
186+
$service = Repository::factory($project);
187+
$client = new HttpClient();
188+
189+
$repository = new RepositoryService($service, $client);
190+
$repository->setStatusPending($build);
191+
178192
send_update_email($handler, $projectid);
179193
sendemail($handler, $projectid);
180194
}
195+
181196
if ($handler instanceof TestingHandler ||
182197
$handler instanceof BuildHandler ||
183198
$handler instanceof ConfigureHandler ||
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* =========================================================================
4+
* Program: CDash - Cross-Platform Dashboard System
5+
* Module: $Id$
6+
* Language: PHP
7+
* Date: $Date$
8+
* Version: $Revision$
9+
* Copyright (c) Kitware, Inc. All rights reserved.
10+
* See LICENSE or http://www.cdash.org/licensing/ for details.
11+
* This software is distributed WITHOUT ANY WARRANTY; without even
12+
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13+
* PURPOSE. See the above copyright notices for more information.
14+
* =========================================================================
15+
*/
16+
17+
use CDash\Config;
18+
use CDash\Lib\Repository\GitHub;
19+
use CDash\Model\Project;
20+
use CDash\Model\Repository;
21+
use Ramsey\Uuid\Uuid;
22+
23+
class RepositoryTest extends PHPUnit_Framework_TestCase
24+
{
25+
public function testFactoryReturnsGitHubService()
26+
{
27+
$apiToken = str_replace('-', '', Uuid::uuid4()->toString());
28+
$config = Config::getInstance();
29+
$config->set('CDASH_GITHUB_API_TOKEN', $apiToken);
30+
31+
$project = new Project();
32+
$project->CvsViewerType = Repository::VIEWER_GITHUB;
33+
$project->CvsUrl = 'https://github.com/foo/bar';
34+
35+
$service = Repository::factory($project);
36+
$this->assertInstanceOf(GitHub::class, $service);
37+
38+
$token = new ReflectionProperty(GitHub::class, 'token');
39+
$token->setAccessible(true);
40+
$this->assertEquals($apiToken, $token->getValue($service));
41+
42+
$owner = new ReflectionProperty(GitHub::class, 'owner');
43+
$owner->setAccessible(true);
44+
$this->assertEquals('foo', $owner->getValue($service));
45+
46+
$repo = new ReflectionProperty(GitHub::class, 'repo');
47+
$repo->setAccessible(true);
48+
$this->assertEquals('bar', $repo->getValue($service));
49+
}
50+
}

0 commit comments

Comments
 (0)