func (ji *jobInfo) UnmarshalJSON(b []byte) error {
	var str apiResponse
	err := json.Unmarshal(b, &str)
	if err != nil {
		return err
	}
	if len(str.Job.Events) == 0 {
		str.Job.Events = str.Events
	}
	if str.Project.ID == "" {
		str.Project = str.Build.Project
	}
	ji.ID = str.ID
	ji.Status = StatusSubmitted
	ji.Project = str.Project.Name
	ji.Command = str.Command
	ji.IPAddress = str.IPAddress
	ji.Message = str.Message
	if str.Build.ID != "" {
		ji.Build = str.Build.ID
	}
	sort.Sort(eventSorter(str.Job.Events))
	if len(str.Job.Events) > 0 {
		firstEvent := str.Job.Events[0]
		lastEvent := str.Job.Events[len(str.Job.Events)-1]
		// Handle terminated status with a prior final status.
		if len(str.Job.Events) > 2 {
			ev := str.Job.Events[len(str.Job.Events)-2]
			if isCompleted(ev.Status) {
				lastEvent = ev
			}
		}
		for _, event := range str.Job.Events {
			if isTimeout(event) {
				// Timeout isn't a Status reported by API
				// but we know the error event was caused by a timeout
				// so report that to user
				lastEvent.Status = StatusTimeout
			}
		}

		ji.Status = strings.ToLower(lastEvent.Status)
		ji.Time = firstEvent.Timestamp
		if eventSorter(str.Job.Events).Completed() {
			ji.Duration = lastEvent.Timestamp.Sub(firstEvent.Timestamp)
		}
	}

	return nil
}
// UnmarshalJSON customizes JSON decoding for BuildInfo.
UnmarshalJSON customizes JSON decoding for BuildInfo.
// UnmarshalJSON customizes JSON decoding for BuildInfo .
func (ji *jobInfo) UnmarshalJSON(b []byte) error {
	var str apiResponse
	err := json.Unmarshal(b, &str)
	if err != nil {
		return err
	}
	if len(str.Job.Events) == 0 {
		str.Job.Events = str.Events
	}
	if str.Project.ID == "" {
		str.Project = str.Build.Project
	}
	ji.ID = str.ID
	ji.Status = StatusSubmitted
	ji.Project = str.Project.Name
	ji.Command = str.Command
	ji.IPAddress = str.IPAddress
	ji.Message = str.Message
	if str.Build.ID != "" {
		ji.Build = str.Build.ID
	}
	sort.Sort(eventSorter(str.Job.Events))
	if len(str.Job.Events) > 0 {
		firstEvent := str.Job.Events[0]
		lastEvent := str.Job.Events[len(str.Job.Events)-1]
		if len(str.Job.Events) > 2 {
			ev := str.Job.Events[len(str.Job.Events)-2]
			if isCompleted(ev.Status) {
				lastEvent = ev
			}
		}
		for _, event := range str.Job.Events {
			if isTimeout(event) {
				lastEvent.Status = StatusTimeout
			}
		}
		ji.Status = strings.ToLower(lastEvent.Status)
		ji.Time = firstEvent.Timestamp
		if eventSorter(str.Job.Events).Completed() {
			ji.Duration = lastEvent.Timestamp.Sub(firstEvent.Timestamp)
		}
	}
	return nil
}
func ( ji * jobInfo ) UnmarshalJSON ( b [ ] byte ) error { var str apiResponse err := json . Unmarshal ( b , & str ) if err != nil { return err } if len ( str . Job . Events ) == 0 { str . Job . Events = str . Events } if str . Project . ID == " " { str . Project = str . Build . Project } ji . ID = str . ID ji . Status = StatusSubmitted ji . Project = str . Project . Name ji . Command = str . Command ji . IPAddress = str . IPAddress ji . Message = str . Message if str . Build . ID != " " { ji . Build = str . Build . ID } sort . Sort ( eventSorter ( str . Job . Events ) ) if len ( str . Job . Events ) > 0 { firstEvent := str . Job . Events [ 0 ] lastEvent := str . Job . Events [ len ( str . Job . Events ) - 1 ] if len ( str . Job . Events ) > 2 { ev := str . Job . Events [ len ( str . Job . Events ) - 2 ] if isCompleted ( ev . Status ) { lastEvent = ev } } for _ , event := range str . Job . Events { if isTimeout ( event ) { lastEvent . Status = StatusTimeout } } ji . Status = strings . ToLower ( lastEvent . Status ) ji . Time = firstEvent . Timestamp if eventSorter ( str . Job . Events ) . Completed ( ) { ji . Duration = lastEvent . Timestamp . Sub ( firstEvent . Timestamp ) } } return nil }
UnmarshalJSON customizes JSON decoding for BuildInfo.
UnmarshalJSON customizes JSON decoding for BuildInfo .
// Handle terminated status with a prior final status. // Timeout isn't a Status reported by API // but we know the error event was caused by a timeout // so report that to user