Skip to content

Commit a2d1a25

Browse files
author
Matt Humphrey
committed
Add Noteable interface
1 parent d131183 commit a2d1a25

File tree

7 files changed

+84
-16
lines changed

7 files changed

+84
-16
lines changed

lib/Gitlab/Api/AbstractApi.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ protected function delete($path, array $parameters = array(), $requestHeaders =
105105

106106
/**
107107
* @param int $id
108+
* @param string $path
108109
* @return string
109110
*/
110111
protected function getProjectPath($id, $path)

lib/Gitlab/HttpClient/HttpClient.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class HttpClient implements HttpClientInterface
5050
private $lastRequest;
5151

5252
/**
53-
* @param array $options
53+
* @param string $baseUrl
54+
* @param array $options
5455
* @param ClientInterface $client
5556
*/
5657
public function __construct($baseUrl, array $options, ClientInterface $client)

lib/Gitlab/Model/Branch.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function createFile($file_path, $content, $commit_message)
112112
{
113113
$data = $this->api('repositories')->createFile($this->project->id, $file_path, $content, $this->name, $commit_message);
114114

115-
return File::fromArray($this->getClient(), $this, $data);
115+
return File::fromArray($this->getClient(), $this->project, $data);
116116
}
117117

118118
/**
@@ -125,7 +125,7 @@ public function updateFile($file_path, $content, $commit_message)
125125
{
126126
$data = $this->api('repositories')->updateFile($this->project->id, $file_path, $content, $this->name, $commit_message);
127127

128-
return File::fromArray($this->getClient(), $this, $data);
128+
return File::fromArray($this->getClient(), $this->project, $data);
129129
}
130130

131131
/**

lib/Gitlab/Model/Issue.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @property-read Milestone $milestone
2121
* @property-read Project $project
2222
*/
23-
class Issue extends AbstractModel
23+
class Issue extends AbstractModel implements Noteable
2424
{
2525
/**
2626
* @var array
@@ -122,13 +122,21 @@ public function open()
122122
}
123123

124124
/**
125-
* @param string $body
125+
* @return Issue
126+
*/
127+
public function reopen()
128+
{
129+
return $this->open();
130+
}
131+
132+
/**
133+
* @param string $comment
126134
* @return Note
127135
*/
128-
public function addComment($body)
136+
public function addComment($comment)
129137
{
130138
$data = $this->api('issues')->addComment($this->project->id, $this->id, array(
131-
'body' => $body
139+
'body' => $comment
132140
));
133141

134142
return Note::fromArray($this->getClient(), $this, $data);
@@ -148,4 +156,16 @@ public function showComments()
148156

149157
return $notes;
150158
}
159+
160+
/**
161+
* @return bool
162+
*/
163+
public function isClosed()
164+
{
165+
if ($this->state == 'closed') {
166+
return true;
167+
}
168+
169+
return false;
170+
}
151171
}

lib/Gitlab/Model/MergeRequest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* @property-read User $assignee
2424
* @property-read Project $project
2525
*/
26-
class MergeRequest extends AbstractModel
26+
class MergeRequest extends AbstractModel implements Noteable
2727
{
2828
/**
2929
* @var array
@@ -127,13 +127,23 @@ public function reopen()
127127
));
128128
}
129129

130+
/**
131+
* @return MergeRequest
132+
*/
133+
public function open()
134+
{
135+
return $this->reopen();
136+
}
137+
130138
/**
131139
* @param string $message
132140
* @return MergeRequest
133141
*/
134142
public function merge($message = null)
135143
{
136-
$data = $this->api('mr')->merge($this->project->id, $this->id, array('merge_commit_message' => $message));
144+
$data = $this->api('mr')->merge($this->project->id, $this->id, array(
145+
'merge_commit_message' => $message
146+
));
137147

138148
return static::fromArray($this->getClient(), $this->project, $data);
139149
}
@@ -149,12 +159,12 @@ public function merged()
149159
}
150160

151161
/**
152-
* @param string $note
162+
* @param string $comment
153163
* @return Note
154164
*/
155-
public function addComment($note)
165+
public function addComment($comment)
156166
{
157-
$data = $this->api('mr')->addComment($this->project->id, $this->id, $note);
167+
$data = $this->api('mr')->addComment($this->project->id, $this->id, $comment);
158168

159169
return Note::fromArray($this->getClient(), $this, $data);
160170
}

lib/Gitlab/Model/Note.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ class Note extends AbstractModel
3232

3333
/**
3434
* @param Client $client
35-
* @param string $type
35+
* @param Noteable $type
3636
* @param array $data
3737
* @return mixed
3838
*/
39-
public static function fromArray(Client $client, $type, array $data)
39+
public static function fromArray(Client $client, Noteable $type, array $data)
4040
{
4141
$comment = new static($type, $data['id'], $client);
4242

@@ -48,11 +48,11 @@ public static function fromArray(Client $client, $type, array $data)
4848
}
4949

5050
/**
51-
* @param string $type
51+
* @param Noteable $type
5252
* @param int $id
5353
* @param Client $client
5454
*/
55-
public function __construct($type, $id = null, Client $client = null)
55+
public function __construct(Noteable $type, $id = null, Client $client = null)
5656
{
5757
$this->setClient($client);
5858
$this->setData('parent_type', get_class($type));

lib/Gitlab/Model/Noteable.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php namespace Gitlab\Model;
2+
3+
interface Noteable
4+
{
5+
/**
6+
* @param string $comment
7+
* @return Note
8+
*/
9+
public function addComment($comment);
10+
11+
/**
12+
* @return Note[]
13+
*/
14+
public function showComments();
15+
16+
/**
17+
* @param string $comment
18+
* @return static
19+
*/
20+
public function close($comment = null);
21+
22+
/**
23+
* @return static
24+
*/
25+
public function open();
26+
27+
/**
28+
* @return static
29+
*/
30+
public function reopen();
31+
32+
/**
33+
* @return bool
34+
*/
35+
public function isClosed();
36+
}

0 commit comments

Comments
 (0)