1

我的问题是我必须以某种方式获取最后一个构建选择构建的人的用户名。有了这些信息,我会将用户名放入数据库。这可能吗?下面是我的 Json 调用方法。

      public JsonResult AllStatuses() //from the json called in the _client view
    {
        var buildStatuses = new List<BuildStatus>();
        var projects = Client.AllProjects();

        var user = Client.AllUsers();

        foreach (var project in projects)
        {                
            try 
            {
                var buildConfigs = Client.BuildConfigsByProjectId(project.Id);

                foreach (var buildConfig in buildConfigs)
                {
                    var b = new BuildStatus();
                    var build = Client.LastBuildByBuildConfigId(buildConfig.Id);
                    var status = Client.LastBuildByBuildConfigId(buildConfig.Id).Status; // Used to loop through BuildConfigID's to find which is a FAILURE, SUCCESS, ERROR, or UNKNOWN
                    b.user = user.ToString();

                    b.id = buildConfig.Id.ToString();

                    // If the date isn't null place the start date in long format
                    if (build.StartDate != null)
                        b.date = build.StartDate.ToString();

                    // If block; set the status based on the BuildconfigID from the var status
                    if (status.Contains("FAILURE")){
                        b.status = "FAILURE";
                    }
                    else if (status.Contains("SUCCESS")){
                        b.status = "SUCCESS";
                    }
                    else if (status.Contains("ERROR")){
                        b.status = "ERROR";
                    }
                    else{
                        b.status = "UNKNOWN";
                    }
                    buildStatuses.Add(b);
                }

            } catch { }

        }
        var query = buildStatuses.OrderBy(x => x.status); // Create a sorted list from Error - Unknown               

        return Json(query, JsonRequestBehavior.AllowGet);
    }
4

1 回答 1

1
var change = Client.LastChangeDetailByBuildConfigId(buildConfig.Id); // Provides the changeID
                    var changeDetail = Client.ChangeDetailsByChangeId(change.Id); // Provides the username, this one populates the usernames

这就是我所需要的,第一个 var 更改找到了更改 ID,但没有填充用户名字段。使用找到的新 changeID 的 changeDetail 填充用户名列表。

于 2012-05-17T14:17:17.057 回答