Exemplo n.º 1
0
        public JobFailureInfo GetFailureInfo(JobId id)
        {
            var commandText = @"
                SELECT Reason,Messages
                FROM Failures
                WHERE Id=@Id";
            using (var command = new SqlCommand(commandText, _connection))
            {
                command.Parameters.AddWithValue("@Id", GetKey(id));

                using (var reader = command.ExecuteReader())
                {
                    if (!reader.Read())
                    {
                        throw new Exception("Missing data");
                    }

                    var reason = reader.GetString(0);
                    var messages = reader.GetString(1).Split(';').ToList();
                    return new JobFailureInfo(
                        (JobFailureReason)(Enum.Parse(typeof(JobFailureReason), reason)),
                        messages);
                }
            }
        }
Exemplo n.º 2
0
 public JobInfo GetJobInfo(JobId id)
 {
     var data = GetJson(id);
     var pr = GetPullRequestInfoCore(id, data);
     var state = GetJobStateCore(data);
     var date = GetJobDateCore(data);
     return new JobInfo(id, pr, state, date);
 }
Exemplo n.º 3
0
 public string GetConsoleText(JobId id)
 {
     var uri = JenkinsUtil.GetConsoleTextUri(id);
     var request = WebRequest.Create(uri);
     using (var reader = new StreamReader(request.GetResponse().GetResponseStream()))
     {
         return reader.ReadToEnd();
     }
 }
Exemplo n.º 4
0
 public JobInfo GetJobInfo(JobId id)
 {
     var data = GetJson(id);
     var sha1 = GetSha1Core(data);
     var state = GetJobStateCore(data);
     var date = GetJobDateCore(data);
     var duration = TimeSpan.FromMilliseconds(data.Value<int>("duration"));
     return new JobInfo(id, state, sha1, date, duration);
 }
Exemplo n.º 5
0
 public JobState GetJobState(JobId id)
 {
     var data = GetJson(id);
     return GetJobStateCore(data);
 }
Exemplo n.º 6
0
 public static Uri GetJobUri(JobId id)
 {
     return GetUri(GetJobPath(id));
 }
Exemplo n.º 7
0
 public static string GetJobPath(JobId id)
 {
     return $"job/{id.Name}/{id.Id}/";
 }
Exemplo n.º 8
0
 private PullRequestInfo GetPullRequestInfoCore(JobId id, JObject data)
 {
     var actions = (JArray)data["actions"];
     return JsonUtil.ParsePullRequestInfo(actions);
 }
Exemplo n.º 9
0
 private JObject GetJson(JobId jobId)
 {
     var path = JenkinsUtil.GetJobPath(jobId);
     return GetJson(path);
 }
Exemplo n.º 10
0
 private static string GetKey(JobId id)
 {
     // TODO: implement
     throw new NotImplementedException();
 }
Exemplo n.º 11
0
        public void InsertRetest(JobId jobId, string sha)
        {
            var commandText = @"
                INSERT INTO dbo.Retests (Id, Sha, Handled)
                VALUES (@Id, @Sha, @Handled)";
            using (var command = new SqlCommand(commandText, _connection))
            {
                var p = command.Parameters;
                p.AddWithValue("@Id", GetKey(jobId));
                p.AddWithValue("@Sha", sha);
                p.AddWithValue("@Handled", 0);

                try
                {
                    command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Could not insert retest {jobId}");
                    Console.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 12
0
 public RetestInfo(JobId jobId, string sha, bool handled, string note = null)
 {
     JobId = jobId;
     Sha = sha;
     Handled = handled;
     Note = note ?? string.Empty;
 }
Exemplo n.º 13
0
 public JobInfo(JobId id, PullRequestInfo pullRequestInfo, JobState state, DateTime date)
 {
     Id = id;
     PullRequestInfo = pullRequestInfo;
     State = state;
     Date = date;
 }
Exemplo n.º 14
0
        public JobResult GetJobResult(JobId id)
        {
            var data = GetJson(id);
            var state = GetJobStateCore(data);
            var date = GetJobDateCore(data);
            var jobInfo = new JobInfo(
                id,
                state,
                GetSha1Core(data),
                date,
                TimeSpan.FromMilliseconds(data.Value<int>("duration")));

            if (state == JobState.Failed)
            {
                var failureInfo = GetJobFailureInfo(id, data);
                return new JobResult(jobInfo, failureInfo);
            }

            return new JobResult(jobInfo);
        }
Exemplo n.º 15
0
 public PullRequestInfo GetPullRequestInfo(JobId id)
 {
     var data = GetJson(id);
     return GetPullRequestInfoCore(id, data);
 }
Exemplo n.º 16
0
        /// <summary>
        /// Attempt to determine the failure reason for the given Job.  This should  only be called on 
        /// jobs that are known to have failed.
        /// </summary>
        private JobFailureInfo GetJobFailureInfo(JobId jobId, JObject data)
        {
            // First look for the test failure information.
            List<string> failedTestList;
            if (TryGetTestFailureReason(jobId, data, out failedTestList))
            {
                Debug.Assert(failedTestList.Count > 0);
                return new JobFailureInfo(JobFailureReason.TestCase, failedTestList);
            }

            // Now look at the console text.
            var consoleText = GetConsoleText(jobId);
            JobFailureInfo failureInfo;
            if (ConsoleTextUtil.TryGetFailureInfo(consoleText, out failureInfo))
            {
                return failureInfo;
            }

            return JobFailureInfo.Unknown;
        }
Exemplo n.º 17
0
        public int GetPullRequestId(JobId id)
        {
            var commandText = @"
                SELECT PullRequestId
                FROM Jobs
                WHERE Id=@Id";
            using (var command = new SqlCommand(commandText, _connection))
            {
                command.Parameters.AddWithValue("@Id", GetKey(id));

                var list = new List<Tuple<JobId, string>>();
                using (var reader = command.ExecuteReader())
                {
                    if (!reader.Read())
                    {
                        throw new Exception("Missing data");
                    }

                    return reader.GetInt32(0);
                }
            }
        }
Exemplo n.º 18
0
        private PullRequestInfo GetPullRequestInfoCore(JobId id, JObject data)
        {
            var actions = (JArray)data["actions"];

            string baseUrl;
            int parentBuildId;
            if (JsonUtil.IsChildJob(actions, out baseUrl, out parentBuildId))
            {
                return GetParentJobPullRequestInfo(baseUrl, parentBuildId);
            }

            // If it's not a child then it is the parent.
            return JsonUtil.ParseParentJobPullRequestInfo(actions);
        }
Exemplo n.º 19
0
 public static string GetConsoleTextPath(JobId id)
 {
     return $"{GetJobPath(id)}consoleText";
 }
Exemplo n.º 20
0
        // TODO: This should be in JenkinsUtil
        private bool TryGetTestFailureReason(JobId jobId, JObject data, out List<string> failedTestList)
        {
            var actions = (JArray)data["actions"];
            foreach (var cur in actions)
            {
                var failCount = cur.Value<int?>("failCount");
                if (failCount != null && failCount.Value != 0)
                {
                    var testReportUrl = cur.Value<string>("urlName");
                    var path = $"{JenkinsUtil.GetJobPath(jobId)}{testReportUrl}/";
                    failedTestList = GetFailedTests(path);
                    return true;
                }
            }

            failedTestList = null;
            return false;
        }
Exemplo n.º 21
0
 public static Uri GetConsoleTextUri(JobId id)
 {
     return GetUri(GetConsoleTextPath(id));
 }
Exemplo n.º 22
0
        public JobResult GetJobResult(JobId id)
        {
            var data = GetJson(id);
            var state = GetJobStateCore(data);
            var date = GetJobDateCore(data);
            var jobInfo = new JobInfo(
                id,
                GetPullRequestInfoCore(id, data),
                state,
                date);

            if (state == JobState.Failed)
            {
                var failureInfo = GetJobFailureInfo(id, data);
                return new JobResult(jobInfo, failureInfo);
            }

            return new JobResult(jobInfo);
        }
Exemplo n.º 23
0
 public JobInfo(JobId id, JobState state, string sha1, DateTime date, TimeSpan duration)
 {
     Id = id;
     State = state;
     Date = date;
     Sha = sha1;
     Duration = duration;
 }