Skip to content

Commit

Permalink
Improve job names (#78)
Browse files Browse the repository at this point in the history
- Matrix jobs with a name, but without any expressions also have the default matrix job `( ... )` name suffix.
- Ignore empty values while building brackets, e.g. `matrix: { "", true }` , `matrix: { null, true }` =>  `<jobname> (true)` and  `matrix: { null }`, `matrix: { "" }` =>  `<jobname>`
  • Loading branch information
ChristopherHX authored May 23, 2022
1 parent c833a57 commit 6902b34
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/Runner.Server/Controllers/MessageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,8 @@ private HookResponse ConvertYaml2(string fileRelativePath, string content, strin
var jobrecord = new TimelineRecord{ Id = jobitem.Id, Name = jobitem.name };
TimelineController.dict[jobitem.TimelineId] = ( new List<TimelineRecord>{ jobrecord }, new System.Collections.Concurrent.ConcurrentDictionary<System.Guid, System.Collections.Generic.List<GitHub.DistributedTask.WebApi.TimelineRecordLogLine>>() );
var jobTraceWriter = new TraceWriter2(line => TimeLineWebConsoleLogController.AppendTimelineRecordFeed(new TimelineRecordFeedLinesWrapper(jobitem.Id, new List<string>{ line }), jobitem.TimelineId, jobitem.Id));
var _jobdisplayname = (from r in run where r.Key.AssertString($"jobs.{jobname} mapping key").Value == "name" select r.Value.ToString()).FirstOrDefault() ?? jobitem.name;
var jobNameToken = (from r in run where r.Key.AssertString($"jobs.{jobname} mapping key").Value == "name" select r.Value).FirstOrDefault();
var _jobdisplayname = jobNameToken?.ToString() ?? jobitem.name;
if(callingJob?.Name != null) {
_jobdisplayname = callingJob.Name + " / " + _jobdisplayname;
}
Expand Down Expand Up @@ -1739,8 +1740,10 @@ private HookResponse ConvertYaml2(string fileRelativePath, string content, strin
var displaySuffix = new StringBuilder();
int z = 0;
foreach (var mk in item) {
displaySuffix.Append(z++ == 0 ? "(" : ", ");
displaySuffix.Append(mk);
if(!string.IsNullOrEmpty(mk)) {
displaySuffix.Append(z++ == 0 ? "(" : ", ");
displaySuffix.Append(mk);
}
}
if(z > 0) {
displaySuffix.Append( ")");
Expand Down Expand Up @@ -1817,10 +1820,7 @@ private HookResponse ConvertYaml2(string fileRelativePath, string content, strin
}
var next = jobTotal > 1 ? new JobItem() { name = jobitem.name, Id = Guid.NewGuid() } : jobitem;
Func<string, string> defJobName = jobname => string.IsNullOrEmpty(displaySuffix) ? jobname : $"{jobname} {displaySuffix}";
var _prejobdisplayname = defJobName(jobname);
if(callingJob?.Name != null) {
_prejobdisplayname = callingJob.Name + " / " + _prejobdisplayname;
}
var _prejobdisplayname = defJobName(_jobdisplayname);
if(jobTotal > 1) {
next.TimelineId = Guid.NewGuid();
// For Runner.Client to show the workflowname
Expand All @@ -1842,10 +1842,13 @@ private HookResponse ConvertYaml2(string fileRelativePath, string content, strin
jobitem.Childs?.Add(next);
TimeLineWebConsoleLogController.AppendTimelineRecordFeed(new TimelineRecordFeedLinesWrapper(next.Id, new List<string>{ $"Evaluate job name" }), next.TimelineId, next.Id);
var templateContext = CreateTemplateContext(matrixJobTraceWriter, workflowContext.FileTable, contextData);
var _jobdisplayname = (from r in run where r.Key.AssertString($"jobs.{jobname} mapping key").Value == "name" select r.Value is StringToken token ? defJobName(token.Value) : GitHub.DistributedTask.ObjectTemplating.TemplateEvaluator.Evaluate(templateContext, "string-strategy-context", r.Value, 0, null, true).AssertString($"jobs.{jobname}.name must be a string").Value).FirstOrDefault() ?? defJobName(jobname);
templateContext.Errors.Check();
if(callingJob?.Name != null) {
_jobdisplayname = callingJob.Name + " / " + _jobdisplayname;
var _jobdisplayname = _prejobdisplayname;
if(jobNameToken != null && !(jobNameToken is StringToken)) {
_jobdisplayname = GitHub.DistributedTask.ObjectTemplating.TemplateEvaluator.Evaluate(templateContext, "string-strategy-context", jobNameToken, 0, null, true).AssertString($"jobs.{jobname}.name must be a string").Value;
templateContext.Errors.Check();
if(callingJob?.Name != null) {
_jobdisplayname = callingJob.Name + " / " + _jobdisplayname;
}
}
next.DisplayName = _jobdisplayname;
TimeLineWebConsoleLogController.AppendTimelineRecordFeed(new TimelineRecordFeedLinesWrapper(next.Id, new List<string>{ $"Evaluate job continueOnError" }), next.TimelineId, next.Id);
Expand Down

0 comments on commit 6902b34

Please sign in to comment.