示例#1
0
<?php

include_once 'config.php';
$youtrack = new YouTrack\Connection(YOUTRACK_URL, YOUTRACK_USERNAME, YOUTRACK_PASSWORD);
$queries = ['#Resolved', '#Fixed'];
$result = $youtrack->executeCountQueries($queries);
/*
array (
    0 => 7286,
    '#Resolved' => 7286,
    1 => 5625,
    '#Fixed' => 5625,
)
*/
if ($result) {
    printf('Results:' . PHP_EOL);
    foreach ($result as $k => $v) {
        if (!is_int($k)) {
            printf('"%s": %s' . PHP_EOL, $k, $v);
        }
    }
}
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Ulrichsg\Getopt\Getopt;
use Ulrichsg\Getopt\Option;
ini_set('display_errors', 'on');
error_reporting(E_ALL);
$getopt = new Getopt([new Option('h', 'host', Getopt::REQUIRED_ARGUMENT), new Option('u', 'username', Getopt::REQUIRED_ARGUMENT), new Option('p', 'password', Getopt::REQUIRED_ARGUMENT), new Option('q', 'query', Getopt::REQUIRED_ARGUMENT), new Option('f', 'pattern', Getopt::OPTIONAL_ARGUMENT), new Option('l', 'limit', Getopt::OPTIONAL_ARGUMENT), new Option('d', 'dry-run', Getopt::OPTIONAL_ARGUMENT)]);
try {
    $getopt->parse();
    $query = $getopt['query'];
    $limit = $getopt['limit'] ? $getopt['limit'] : 100;
    $dryRun = $getopt['dry-run'] ? true : false;
    $youtrack = new YouTrack\Connection($getopt['host'], $getopt['username'], $getopt['password']);
    $pattern = $getopt['pattern'];
    echo 'Executing query: "' . $query . '"' . PHP_EOL;
    $issues = $youtrack->getIssuesByFilter($query, null, $limit);
    echo count($issues) . ' issues found' . PHP_EOL;
    foreach ($issues as $issue) {
        $attachments = $issue->getAttachments();
        $ac = count($attachments);
        $ts = substr($issue->created, 0, -3);
        $created = new \DateTime('@' . $ts);
        echo $issue->getId() . ', created: ' . $created->format('Y-m-d H:i:s') . ': ' . $ac . ' attachments.' . PHP_EOL;
        foreach ($attachments as $attachment) {
            echo '    ID: ' . $attachment->getId() . ' (' . $attachment->getName() . ')';
            if (!$pattern || preg_match('/' . $pattern . '/', $attachment->getName())) {
                if (!$dryRun) {
                    $success = $youtrack->deleteAttachment($issue, $attachment);
                    if ($success) {
                        echo ' deleted';
<?php

include_once 'config.php';
$youtrack = new YouTrack\Connection(YOUTRACK_URL, YOUTRACK_USERNAME, YOUTRACK_PASSWORD);
// make sure, this exists!
$issues = ['Sandbox-24', 'Sandbox-25'];
foreach ($issues as $issueId) {
    $issue = $youtrack->getIssue($issueId);
    $attachments = $issue->getAttachments();
    foreach ($attachments as $attachment) {
        echo $attachment->getName() . PHP_EOL;
        // here you can play with your file
        $content = $attachment->fetchContent();
        file_put_contents('./files/' . $attachment->getName(), $content);
    }
}
示例#4
0
<?php

$root = true;
include_once 'config.php';
$youtrack = new YouTrack\Connection(YOUTRACK_URL, YOUTRACK_USERNAME, YOUTRACK_PASSWORD);
$user = '******';
$roles = [];
try {
    $roles = $youtrack->getUserRoles($user);
} catch (\YouTrack\NotAuthorizedException $e) {
    $message = 'Got NotAuthorizedException!';
    if ($error = $e->getYouTrackError()) {
        $message = $error->__get("error");
    }
    echo sprintf($message) . PHP_EOL;
}
if ($roles) {
    printf('Results:' . PHP_EOL);
    foreach ($roles as $role) {
        $refs = $role->getProjectRefs();
        $projectRefs = '';
        if (!empty($refs)) {
            $projectRefs = [];
            foreach ($refs as $ref) {
                $projectRefs[] = $ref->getId();
            }
            $projectRefs = ' (' . implode(', ', $projectRefs) . ')';
        }
        echo sprintf(' - %s%s', $role->getName(), $projectRefs) . PHP_EOL;
    }
}
示例#5
0
<?php

include_once 'config.php';
$youtrack = new YouTrack\Connection(YOUTRACK_URL, YOUTRACK_USERNAME, YOUTRACK_PASSWORD);
$issueId = 'Sandbox-25';
$command = 'Assignee me';
try {
    $result = $youtrack->executeCommand($issueId, $command);
    if ($result) {
        echo "Command '{$command}' executed on issue '{$issueId}'." . PHP_EOL;
    } else {
        echo "The command was not executed" . PHP_EOL;
    }
} catch (\YouTrack\NotAuthorizedException $e) {
    echo $e->getMessage() . PHP_EOL;
}
示例#6
0
<?php

$root = true;
// to see results from getAssigneesUsers, you need to have the right permissions
include_once 'config.php';
$youtrack = new YouTrack\Connection(YOUTRACK_URL, YOUTRACK_USERNAME, YOUTRACK_PASSWORD);
$projects = $youtrack->getAccessibleProjects(true);
printf('You have %d projects:' . PHP_EOL, count($projects));
foreach ($projects as $project) {
    printf(' - %s' . PHP_EOL, $project->getShortName());
    $systems = $project->getSubsystems();
    printf(' > %d subsystems' . PHP_EOL, count($systems));
    foreach ($systems as $sys) {
        printf(' -- %s' . PHP_EOL, $sys->__get('name'));
    }
    $users = $project->getAssigneesUsers();
    printf(' > %d users' . PHP_EOL, count($users));
    foreach ($users as $user) {
        printf(' -- %s' . PHP_EOL, $user->__get('login'));
    }
    echo PHP_EOL;
}
示例#7
0
<?php

$root = true;
include_once 'config.php';
$youtrack = new YouTrack\Connection(YOUTRACK_URL, YOUTRACK_USERNAME, YOUTRACK_PASSWORD);
$users = array();
try {
    $users = $youtrack->getUsers();
} catch (\YouTrack\NotAuthorizedException $e) {
    $message = 'Got NotAuthorizedException!';
    if ($error = $e->getYouTrackError()) {
        $message = $error->__get("error");
    }
    echo sprintf($message) . PHP_EOL;
}
if ($users) {
    printf('Results:' . PHP_EOL);
    foreach ($users as $user) {
        echo sprintf(' - %s', $user->getLogin()) . PHP_EOL;
    }
}
示例#8
0
<?php

include_once 'config.php';
$youtrack = new YouTrack\Connection(YOUTRACK_URL, YOUTRACK_USERNAME, YOUTRACK_PASSWORD);
$issueId = 'Sandbox-57';
$attachment = new YouTrack\Attachment();
$attachment->setUrl(dirname(__FILE__) . '/attachment.txt');
$attachment->setName('mylog');
$result = $youtrack->createAttachmentFromAttachment($issueId, $attachment);
/*
array(2) {
 'content' =>
 string(194) "{"id":"62-2910","url":"http://nepda.myjetbrains.com/youtrack/_persistent/mylog2.txt?file=62-2910&v=0&c=false","name":"mylog2.txt","authorLogin":"******","group":"All Users","created":1417519013543}"
 'response' =>
 array(26) {
   'url' =>
   string(82) "https://nepda.myjetbrains.com/youtrack/rest/issue/Sandbox-57/attachment?name=mylog"
   'content_type' =>
   string(31) "application/json; charset=utf-8"
   'http_code' =>
   int(201)
   'header_size' =>
   int(427)
   'request_size' =>
   int(551)
   'filetime' =>
   int(-1)
   'ssl_verify_result' =>
   int(0)
   'redirect_count' =>
   int(0)
<?php

include_once 'config.php';
$youtrack = new YouTrack\Connection(YOUTRACK_URL, YOUTRACK_USERNAME, YOUTRACK_PASSWORD);
// make sure, this exists!
$issues = $youtrack->getIssuesByFilter('#Unresolved for:me');
foreach ($issues as $issue) {
    echo $issue->getId() . PHP_EOL;
}
示例#10
0
<?php

include_once 'config.php';
$youtrack = new YouTrack\Connection(YOUTRACK_URL, YOUTRACK_USERNAME, YOUTRACK_PASSWORD);
$params = array('priority' => 'Higher', 'type' => 'Auto-reported CLI exception', 'description' => "The full text issue description");
$issue = $youtrack->createIssue('Sandbox', 'Create a basic issue for example', $params);
if ($issue) {
    printf('Issue %s created' . PHP_EOL, $issue->getId());
}