我正在开发一个 C# 工具,用于连接 JIRA SOAP API。我已阅读可以在这里找到的文档: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 的用户拥有一些管理员权限
关于api - JIRA SOAP API : get the list of users,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1093564/