WorklogEndpoint::listWorklog()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright © 2017 Toan Nguyen. All rights reserved.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Gojira\Jira\Endpoint;
10
11
use Gojira\Framework\Serializer\Serializer;
12
use Gojira\Api\Endpoint\EndpointInterface;
13
use Gojira\Api\Request\HttpMethod;
14
15
/**
16
 * Endpoint for JIRA REST /worklog
17
 *
18
 * @package Gojira\Jira\Endpoint
19
 * @author  Toan Nguyen <[email protected]>
20
 */
21
class WorklogEndpoint extends IssueEndpoint implements EndpointInterface
22
{
23
    const EP_WORKLOG = 'worklog';
24
25
    const PARAM_ADJUST_ESTIMATE = 'adjustEstimate';
26
    const PARAM_NEW_ESTIMATE = 'newEstimate';
27
    const PARAM_REDUCE_BY = 'reduceBy';
28
    const PARAM_INCREASE_BY = 'increaseBy';
29
30
    const PAYLOAD_COMMENT = 'comment';
31
    const PAYLOAD_VISIBILITY = 'visibility';
32
    const PAYLOAD_VISIBILITY_TYPE = 'type';
33
    const PAYLOAD_VISIBILITY_VALUE = 'value';
34
    const PAYLOAD_STARTED = 'started';
35
    const PAYLOAD_TIME_SPENT = 'timeSpent';
36
    const PAYLOAD_TIME_SPENT_SECONDS = 'timeSpentSeconds';
37
38
    /**
39
     * Get list of worklogs for an issue [STATUS 200]
40
     *
41
     * @param string $issue JIRA ticket number
42
     *
43
     * @return array
44
     */
45
    public function listWorklog($issue)
46
    {
47
        return $this->apiClient->callEndpoint(__e('%1/%2/%3', self::ENDPOINT, $issue, self::EP_WORKLOG));
48
    }
49
50
    /**
51
     * Add worklog for an issue [STATUS 201]
52
     *
53
     * @param string      $issue          JIRA ticket number
54
     *
55
     * @param string      $timeSpent      How much time spent (e.g. '3h 30m')
56
     * @param string|null $comment        [optional] Comment
57
     * @param string|null $started        [optional] Set date of work
58
     *
59
     * @param string|null $adjustEstimate [optional] Allows you to provide specific instructions to update the
60
     *                                    remaining time estimate of the issue. Valid values are
61
     *                                    "new" - sets the estimate to a specific value
62
     *                                    "leave"- leaves the estimate as is
63
     *                                    "manual" - specify a specific amount to increase remaining estimate by
64
     *                                    "auto"- Default option. Will automatically adjust the value based on the new
65
     *                                    timeSpent specified on the worklog
66
     * @param string|null $newEstimate    (required when "new" is selected for adjustEstimate) the new value for the
67
     *                                    remaining estimate field. e.g. "2d"
68
     * @param string|null $reduceBy       (required when "manual" is selected for adjustEstimate) the amount to reduce
69
     *                                    the remaining estimate by e.g. "2d"
70
     *
71
     * @return array
72
     */
73 View Code Duplication
    public function addWorklog(
74
        $issue,
75
        $timeSpent,
76
        $comment = null,
77
        $started = null,
78
        $adjustEstimate = null,
79
        $newEstimate = null,
80
        $reduceBy = null
81
    ) {
82
        $parameters = [
83
            self::PARAM_ADJUST_ESTIMATE => $adjustEstimate,
84
            self::PARAM_NEW_ESTIMATE => $newEstimate,
85
            self::PARAM_REDUCE_BY => $reduceBy,
86
        ];
87
        $payload = [
88
            self::PAYLOAD_COMMENT => $comment,
89
            self::PAYLOAD_TIME_SPENT => $timeSpent,
90
            self::PAYLOAD_STARTED => $started
91
        ];
92
93
        return $this->apiClient->callEndpoint(
94
            __e('%1/%2/%3', self::ENDPOINT, $issue, self::EP_WORKLOG),
95
            $parameters,
96
            Serializer::encode($payload),
97
            HttpMethod::POST
98
        );
99
    }
100
101
    /**
102
     * Update worklog for an issue [STATUS 200]
103
     *
104
     * @param string      $issue          JIRA ticket number
105
     * @param string      $worklogId      Worklog ID
106
     *
107
     * @param string      $timeSpent      How much time spent (e.g. '3h 30m')
108
     * @param string|null $comment        [optional] Comment
109
     * @param string|null $started        [optional] Set date of work
110
     *
111
     * @param string|null $adjustEstimate [optional] Allows you to provide specific instructions to update the
112
     *                                    remaining time estimate of the issue. Valid values are
113
     *                                    "new" - sets the estimate to a specific value
114
     *                                    "leave"- leaves the estimate as is
115
     *                                    "manual" - specify a specific amount to increase remaining estimate by
116
     *                                    "auto"- Default option. Will automatically adjust the value based on the new
117
     *                                    timeSpent specified on the worklog
118
     * @param string|null $newEstimate    (required when "new" is selected for adjustEstimate) the new value for the
119
     *                                    remaining estimate field. e.g. "2d"
120
     *
121
     * @return array
122
     */
123 View Code Duplication
    public function updateWorklog(
124
        $issue,
125
        $worklogId,
126
        $timeSpent,
127
        $comment = null,
128
        $started = null,
129
        $adjustEstimate = null,
130
        $newEstimate = null
131
    ) {
132
        $parameters = [
133
            self::PARAM_ADJUST_ESTIMATE => $adjustEstimate,
134
            self::PARAM_NEW_ESTIMATE => $newEstimate
135
        ];
136
        $payload = [
137
            self::PAYLOAD_COMMENT => $comment,
138
            self::PAYLOAD_TIME_SPENT => $timeSpent,
139
            self::PAYLOAD_STARTED => $started
140
        ];
141
142
        return $this->apiClient->callEndpoint(
143
            __e('%1/%2/%3/%4', self::ENDPOINT, $issue, self::EP_WORKLOG, $worklogId),
144
            $parameters,
145
            Serializer::encode($payload),
146
            HttpMethod::PUT
147
        );
148
    }
149
150
    /**
151
     * Delete worklog for an issue [STATUS 204]
152
     *
153
     * @param string      $issue          JIRA ticket number
154
     * @param string      $worklogId      Worklog ID
155
     *
156
     * @param string|null $adjustEstimate [optional] Allows you to provide specific instructions to update the
157
     *                                    remaining time estimate of the issue. Valid values are
158
     *                                    "new" - sets the estimate to a specific value
159
     *                                    "leave"- leaves the estimate as is
160
     *                                    "manual" - specify a specific amount to increase remaining estimate by
161
     *                                    "auto"- Default option. Will automatically adjust the value based on the new
162
     *                                    timeSpent specified on the worklog
163
     * @param string|null $newEstimate    (required when "new" is selected for adjustEstimate) the new value for the
164
     *                                    remaining estimate field. e.g. "2d"
165
     * @param string|null $increaseBy     (required when "manual" is selected for adjustEstimate) the amount to
166
     *                                    increase the remaining estimate by e.g. "2d"
167
     *
168
     * @return array
169
     */
170
    public function deleteWorklog($issue, $worklogId, $adjustEstimate = null, $newEstimate = null, $increaseBy = null)
171
    {
172
        $parameters = [
173
            self::PARAM_ADJUST_ESTIMATE => $adjustEstimate,
174
            self::PARAM_NEW_ESTIMATE => $newEstimate,
175
            self::PARAM_INCREASE_BY => $increaseBy,
176
        ];
177
178
        return $this->apiClient->callEndpoint(
179
            __e('%1/%2/%3/%4', self::ENDPOINT, $issue, self::EP_WORKLOG, $worklogId),
180
            $parameters,
181
            null,
182
            HttpMethod::DELETE
183
        );
184
    }
185
}
186