Skip to content

Feature/jira transitionbyname #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 58 additions & 23 deletions src/Jira/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,24 @@ public function editIssue($issueKey, $params)
}


/**
* Delete issue
*
* @param $issueKey should be YOURPROJ-221
* @param $deleteSubtasks if all subtask should be deleted
* @return mixed
*/
public function deleteIssue($issueKey, $deleteSubtasks = 'true')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is submitted as #53 PR and surely must be removed from here.

{
return $this->api(
self::REQUEST_DELETE, sprintf("/rest/api/2/issue/%s", $issueKey),
array (
'deleteSubtasks' => $deleteSubtasks
)
);
}


public function getAttachment($attachmentId)
{
$result = $this->api(self::REQUEST_GET, "/rest/api/2/attachment/$attachmentId", array(), true);
Expand Down Expand Up @@ -253,6 +271,8 @@ public function getTransitions($issueKey, $params)
return $this->api(self::REQUEST_GET, sprintf("/rest/api/2/issue/%s/transitions", $issueKey), $params);
}



Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove extra line, because methods should separated by 1 line, not 2.

/**
* transation a ticket
*
Expand All @@ -267,6 +287,43 @@ public function transition($issueKey, $params)
return $this->api(self::REQUEST_POST, sprintf("/rest/api/2/issue/%s/transitions", $issueKey), $params);
}

/**
* transation by step name
*
*
* @param $issueKey like YOURPROJ-22
* @param $stepName Step name like 'Done' or 'To Do'
* @param $params (array of parameters from JIRA API)
* @return mixed
*/
public function transitionByStepName($issueKey, $stepName, $params = array())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does step term come from? I haven't seen this concept in JIRA docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StepName isn't a jira term, but it's easy to use step name (the name of the button above issue) to navigate. It's just easier to reffer it as text than as ID - even if text could be changed and ID cannot. but it would be more understandable if you would do:
$jira->updatejira(...);
$jira->transitionByStepName('Approved');
$jira->updatejira(..);
$jira->transitionByStepName('Completed');

I think, that transitionByName($transitionName, $issueKey, $params = array()) would be a better name, because it executes transition by name. The issue on which transition is executed is important, but not so much.

Anyway we're not making a release tomorrow, so we can rename this one later on as well.

P.S.
Please answer to inline comments also inline to keep discussions on separate topics separated.

2016-02-29_1919

{
$result = array();
// get available transitions
$tmp_transitions = $this->getTransitions($issueKey, array());
$tmp_transitions_result = $tmp_transitions->getResult();
$transitions = $tmp_transitions_result['transitions'];

// search id for closing ticket
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is a copy/paste and only adds a confusion.

foreach ($transitions as $v) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boy scout rule: rename the $v variable to something more understandable (e.g. $transitionData).

// Close ticket if required id was found
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is a copy/paste and only adds a confusion.

if ($v['name'] == $stepName) {
$result = $this->transition(
$issueKey,
array_merge($params,
array(
'transition' => array(
'id' => $v['id']
)
)
)
);
break;
}
}
return $result;
}

/**
* get available issue types
*
Expand Down Expand Up @@ -547,31 +604,9 @@ public function setWatchers($issueKey, $watchers)
* @param $issueKey
* @return mixed
*
* @TODO: should have parameters? (e.g comment)
*/
public function closeIssue($issueKey)
{
$result = array();
// get available transitions
$tmp_transitions = $this->getTransitions($issueKey, array());
$tmp_transitions_result = $tmp_transitions->getResult();
$transitions = $tmp_transitions_result['transitions'];

// search id for closing ticket
foreach ($transitions as $v) {
// Close ticket if required id was found
if ($v['name'] == "Close Issue") {
$result = $this->transition(
$issueKey,
array(
'transition' => array(
'id' => $v['id']
)
)
);
break;
}
}
return $result;
return $this->transitionByStepName($issueKey,'Close Issue');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after comma.

}
}
12 changes: 7 additions & 5 deletions src/Jira/Api/Client/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ public function sendRequest($method, $url, $data = array(), $endpoint, Authentic
} else {
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
}
} else {
if ($method == "PUT") {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
}
} elseif ($method == "DELETE") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is submitted as #53 PR and surely must be removed from here.

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this empty line.

} elseif ($method == "PUT") {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
}


$data = curl_exec($curl);

Expand Down