私は、JIRA SOAP API をインターフェースする C# のツールに取り組んでいます。ここにあるドキュメントを読みました: http://docs.atlassian.com/software/jira/docs/api/rpc-jira-plugin/latest/index.html
特定のプロジェクトに割り当て可能なすべてのユーザーのリストを取得する方法を知っている人はいますか? 私はまだそれを行う方法を見つけることができませんでした...
私は、JIRA SOAP API をインターフェースする C# のツールに取り組んでいます。ここにあるドキュメントを読みました: http://docs.atlassian.com/software/jira/docs/api/rpc-jira-plugin/latest/index.html
特定のプロジェクトに割り当て可能なすべてのユーザーのリストを取得する方法を知っている人はいますか? 私はまだそれを行う方法を見つけることができませんでした...
わかりました、今日は体調が良くなければならないので、これが私の問題の解決策です
/// <summary>
/// object interface to the JIRA API
/// </summary>
private readonly JiraSoapServiceClient _JiraService;
/// <summary>
/// authentication token returned by the login method
/// that can be used on all other SOAP methods
/// </summary>
private readonly string _Token;
/// <summary>
/// name of the RemoteProjectRole "Developers"
/// </summary>
private const string DEVELOPER_ROLE = "Developers";
/// <summary>
/// id of the RemoteProjectRole "Developers"
/// </summary>
private static long? _DeveloperId;
/// <summary>
/// return the list of the names of all the users who have
/// the role "Developers" in a project
/// </summary>
/// <param name="project"></param>
/// <returns></returns>
public List<string> GetUsersForProject(string project)
{
List<string> users = new List<string>();
try
{
// get the RemoteProject
RemoteProject rp = _JiraService.getProjectByKey(_Token, project);
// get the "Developers" Prject Role
RemoteProjectRole developerRole = getDeveloperRole();
if (developerRole != null)
{
// we can use this method only if the user logged in is an administrator
RemoteRoleActors actors = _JiraService.getProjectRoleActors(_Token, developerRole, rp);
foreach (RemoteRoleActor actor in actors.roleActors)
{
foreach (RemoteUser user in actor.users)
{
users.Add(user.name);
}
}
}
}
catch (Exception ex)
{
// TODO log the error
users.Clear();
}
users.Sort();
return users;
}
/// <summary>
/// return the RemoteProjectRole "Developers"
/// </summary>
/// <returns></returns>
private RemoteProjectRole getDeveloperRole()
{
RemoteProjectRole developerRole = null;
if (_DeveloperId == null)
{
// the first time we call this function we don't know the id of this role
// that's why we are obliged to find it with a foreach on all the project roles
foreach (RemoteProjectRole role in _JiraService.getProjectRoles(_Token))
{
if (role.name == DEVELOPER_ROLE)
{
developerRole = role;
_DeveloperId = role.id;
break;
}
}
}
else
{
// we have the id so we can get directly the RemoteProjectRole from the JIRA SOAP API
developerRole = _JiraService.getProjectRole(_Token, (long)_DeveloperId);
}
return developerRole;
}
コメントは大歓迎です。明らかに、異なる役割に同じ方法を使用できます。JIRA api へのログインに使用するユーザーが何らかの管理者権限を持っていることを確認する必要があります。
Flex から getProjectRoleActors を (少なくとも) 呼び出す場合、ログインしているユーザーが管理者でない場合、予期されるエラーや空の応答ではなく、応答がまったく得られないことに注意してください。ユーザーを管理者にすることを忘れないでください。
一般的な「Get Users」タイプのコマンドがなく、質問をする前にプロジェクトとロール オブジェクトをロードする必要があるため、少し直感に反します。
これはPHPでの同じ基本的な実装です(私が書いたばかりなので)が、「開発者」ではなく「ユーザー」の役割をキーオフしています:
$base_url = 'https://yourjira.domain.com';
$wsdl = $base_url . '/rpc/soap/jirasoapservice-v2?wsdl';
$username = 'username';
$password = 'password';
$client = new SoapClient($wsdl);
try {
$token = $client->login($username, $password);
}
catch (SoapFault $fault) {
echo "Error logging in to JIRA";
print_r($fault);
}
$code = 'MYPROJECT'
$project = $client->getProjectByKey($token, $code);
$role = $client->getProjectRole($token, 10000); // 10000 is typically the "users" role
$users = $client->getProjectRoleActors($token, $role, $project);
print_r($users);