Skip to content

Commit

Permalink
#726 Node-type names used in more than one class must reside in Stand…
Browse files Browse the repository at this point in the history
…ard_Names.

Avoid magic strings (and their duplicates).
  • Loading branch information
koschke committed Sep 16, 2024
1 parent e47cab2 commit ca6da56
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
15 changes: 15 additions & 0 deletions Assets/SEE/DataModel/DG/StandardNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ public static class VCS
/// Prefix for VCS metrics.
/// </summary>
public const string Prefix = Metrics.Prefix + VCSPrefix;

/// <summary>
/// The number of lines of code added for a file that was changed between two commits.
/// </summary>
Expand All @@ -285,12 +286,26 @@ public static class VCS
/// The truck factor of a file (core-devs metric).
/// </summary>
public const string TruckNumber = Prefix + "Truck_Number";

/// <summary>
/// String attribute for the list of authors of a file.
/// </summary>
/// <remarks>Note that this is not actually a numeric metric but a list of
/// author names seperated by a comma.</remarks>
public const string AuthorAttributeName = VCSPrefix + "Authors";

/// <summary>
/// Name of node type used for files.
/// </summary>
public const string FileType = "File";
/// <summary>
/// Name of node type used for directories.
/// </summary>
public const string DirectoryType = "Directory";
/// <summary>
/// Name of node type used for repositories.
/// </summary>
public const string RepositoryType = "Repository";
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Assets/SEE/Game/CityRendering/AuthorSphereRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public partial class GraphRenderer
public void DrawAuthorSpheres(IDictionary<Node, GameObject> nodeMap, GameObject parent)
{
List<string> authors =
nodeMap.Keys.Where(x => x.Type == "file")
nodeMap.Keys.Where(x => x.Type == DataModel.DG.VCS.FileType)
.SelectMany(x => x.StringAttributes.Where(y => y.Key == DataModel.DG.VCS.AuthorAttributeName))
.SelectMany(x => x.Value.Split(","))
.Distinct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private Graph GetGraph(Graph graph, Action<float> changePercentage, BranchCity b

string repositoryName = Filenames.InnermostDirectoryName(repositoryPath);

GraphUtils.NewNode(graph, repositoryName, GraphUtils.RepositoryTypeName, repositoryName);
GraphUtils.NewNode(graph, repositoryName, DataModel.DG.VCS.RepositoryType, repositoryName);

// Assuming that CheckAttributes() was already executed so that the date string is neither empty nor malformed.
DateTime timeLimit = DateTime.ParseExact(branchCity.Date, "dd/MM/yyyy", CultureInfo.InvariantCulture);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private Graph GetGraphOfCommit(string repoName, Commit currentCommit, List<Commi
{
BasePath = GitRepository.RepositoryPath.Path
};
GraphUtils.NewNode(g, repoName + "-Evo", GraphUtils.RepositoryTypeName, repoName + "-Evo");
GraphUtils.NewNode(g, repoName + "-Evo", DataModel.DG.VCS.RepositoryType, repoName + "-Evo");

g.StringAttributes.Add("CommitTimestamp", currentCommit.Author.When.Date.ToString("dd/MM/yyy"));
g.StringAttributes.Add("CommitId", currentCommit.Sha);
Expand Down
23 changes: 2 additions & 21 deletions Assets/SEE/GraphProviders/VCS/GraphUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,6 @@ namespace SEE.GraphProviders.VCS
/// </example>
public static class GraphUtils
{
#region Contants

/// <summary>
/// Typename used for files.
/// </summary>
private const string fileType = "File";

/// <summary>
/// Typename used for directories.
/// </summary>
private const string directoryType = "Directory";

/// <summary>
/// Typename used for repositories.
/// </summary>
public const string RepositoryTypeName = "Repository";

#endregion

/// <summary>
/// Creates and returns a new node to <paramref name="graph"/>.
/// </summary>
Expand Down Expand Up @@ -106,7 +87,7 @@ private static Node GetOrAddNode(string fullRelativePath, string path, Node pare

// Create a new file node and return it.
Node addedFileNode = NewNode(graph, fullRelativePath + idSuffix,
fileType, path);
DataModel.DG.VCS.FileType, path);
addedFileNode.Filename = path;
addedFileNode.Directory = fileDir;
parent.AddChild(addedFileNode);
Expand All @@ -126,7 +107,7 @@ private static Node GetOrAddNode(string fullRelativePath, string path, Node pare

// Create a new directory node.
Node addedDirectoryNode = NewNode(graph, directoryName,
directoryType, directoryName);
DataModel.DG.VCS.DirectoryType, directoryName);
addedDirectoryNode.Directory = directoryName;
parent.AddChild(addedDirectoryNode);
return GetOrAddNode(fullRelativePath, String.Join(Path.AltDirectorySeparatorChar, pathSegments.Skip(1)),
Expand Down

0 comments on commit ca6da56

Please sign in to comment.