CollabHistoryItemFactory.cs
4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Collaboration;
using UnityEngine;
#if UNITY_2019_1_OR_NEWER
using UnityEngine.UIElements;
#else
using UnityEngine.Experimental.UIElements;
using UnityEngine.Experimental.UIElements.StyleEnums;
#endif
namespace UnityEditor.Collaboration
{
internal class CollabHistoryItemFactory : ICollabHistoryItemFactory
{
const int k_MaxChangesPerRevision = 10;
public IEnumerable<RevisionData> GenerateElements(IEnumerable<Revision> revisions, int totalRevisions, int startIndex, string tipRev, string inProgressRevision, bool revisionActionsEnabled, bool buildServiceEnabled, string currentUser)
{
int index = startIndex;
foreach (var rev in revisions)
{
index++;
var current = rev.revisionID == tipRev;
// Calculate build status
BuildState buildState = BuildState.None;
int buildFailures = 0;
if (rev.buildStatuses != null && rev.buildStatuses.Length > 0)
{
bool inProgress = false;
foreach (CloudBuildStatus buildStatus in rev.buildStatuses)
{
if (buildStatus.complete)
{
if (!buildStatus.success)
{
buildFailures++;
}
}
else
{
inProgress = true;
break;
}
}
if (inProgress)
{
buildState = BuildState.InProgress;
}
else if (buildFailures > 0)
{
buildState = BuildState.Failed;
}
else
{
buildState = BuildState.Success;
}
}
else if (current && !buildServiceEnabled)
{
buildState = BuildState.Configure;
}
// Calculate the number of changes performed on files and folders (not meta files)
var paths = new Dictionary<string, ChangeData>();
foreach (ChangeAction change in rev.entries)
{
if (change.path.EndsWith(".meta"))
{
var path = change.path.Substring(0, change.path.Length - 5);
// Actions taken on meta files are secondary to any actions taken on the main file
if (!paths.ContainsKey(path))
paths[path] = new ChangeData() {path = path, action = change.action};
}
else
{
paths[change.path] = new ChangeData() {path = change.path, action = change.action};
}
}
var displayName = (rev.author != currentUser) ? rev.authorName : "You";
var item = new RevisionData
{
id = rev.revisionID,
index = totalRevisions - index + 1,
timeStamp = TimeStampToDateTime(rev.timeStamp),
authorName = displayName,
comment = rev.comment,
obtained = rev.isObtained,
current = current,
inProgress = (rev.revisionID == inProgressRevision),
enabled = revisionActionsEnabled,
buildState = buildState,
buildFailures = buildFailures,
changes = paths.Values.Take(k_MaxChangesPerRevision).ToList(),
changesTotal = paths.Values.Count,
changesTruncated = paths.Values.Count > k_MaxChangesPerRevision,
};
yield return item;
}
}
private static DateTime TimeStampToDateTime(double timeStamp)
{
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
dateTime = dateTime.AddSeconds(timeStamp).ToLocalTime();
return dateTime;
}
}
}