我正在使用C#中的一個工具來連接JIRA SOAP API。我已閱讀文檔可以在這裏找到:JIRA SOAP API:獲取用戶列表
有誰知道我怎麼能得到一個特定項目的所有可分配用戶的列表?我一直沒能找到如何做到這一點尚未...
我正在使用C#中的一個工具來連接JIRA SOAP API。我已閱讀文檔可以在這裏找到:JIRA SOAP API:獲取用戶列表
有誰知道我怎麼能得到一個特定項目的所有可分配用戶的列表?我一直沒能找到如何做到這一點尚未...
好,我一定要在更好的狀態,所以今天在這裏是我的問題的解決方案
/// <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時,如果您登錄的用戶不是管理員,那麼而不是如你所期望的那樣得到一個錯誤或空的響應,你根本沒有得到任何迴應,這是非常令人沮喪的,直到你記得讓用戶成爲管理員。
這有點違反直覺,因爲沒有通用的「獲取用戶」類型命令,並且您需要先加載項目和角色對象,然後才能問問題。
下面是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);