-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitSource.hpp
More file actions
93 lines (80 loc) · 3.22 KB
/
Copy pathGitSource.hpp
File metadata and controls
93 lines (80 loc) · 3.22 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
#ifndef RUNCPP2_DATA_GIT_SOURCE_HPP
#define RUNCPP2_DATA_GIT_SOURCE_HPP
#include "runcpp2/Data/SubmoduleInitType.hpp"
#include "runcpp2/ParseUtil.hpp"
#include "runcpp2/LibYAML_Wrapper.hpp"
#include "DSResult/DSResult.hpp"
#include "ssLogger/ssLog.hpp"
#include <string>
#include <vector>
namespace runcpp2
{
namespace Data
{
struct GitSource
{
std::string URL;
std::string Branch;
bool FullHistory = false;
SubmoduleInitType CurrentSubmoduleInitType = SubmoduleInitType::SHALLOW;
inline bool ParseYAML_Node(YAML::ConstNodePtr node)
{
std::vector<NodeRequirement> requirements =
{
NodeRequirement("URL", YAML::NodeType::Scalar, true, false),
NodeRequirement("Branch", YAML::NodeType::Scalar, false, false),
NodeRequirement("FullHistory", YAML::NodeType::Scalar, false, false),
NodeRequirement("SubmoduleInitType", YAML::NodeType::Scalar, false, false)
};
if(!CheckNodeRequirements(node, requirements))
{
ssLOG_ERROR("GitSource: Failed to meet requirements");
return false;
}
URL = node->GetMapValueScalar<std::string>("URL").value();
if(ExistAndHasChild(node, "Branch"))
{
Branch = node->GetMapValueScalar<std::string>("Branch").DS_TRY_ACT(return false);
}
if(ExistAndHasChild(node, "FullHistory"))
{
FullHistory = node->GetMapValueScalar<bool>("FullHistory").DS_TRY_ACT(return false);
}
if(ExistAndHasChild(node, "SubmoduleInitType"))
{
std::string submoduleTypeString =
node->GetMapValueScalar<std::string>("SubmoduleInitType").value();
CurrentSubmoduleInitType = StringToSubmoduleInitType(submoduleTypeString);
if(CurrentSubmoduleInitType == SubmoduleInitType::COUNT)
{
ssLOG_ERROR("GitSource: Invalid submodule init type " << submoduleTypeString);
return false;
}
}
return true;
}
inline std::string ToString(std::string indentation) const
{
std::string out;
out += indentation + "Git:\n";
out += indentation + " URL: " + GetEscapedYAMLString(URL) + "\n";
if(!Branch.empty())
out += indentation + " Branch: " + GetEscapedYAMLString(Branch) + "\n";
out += indentation + " FullHistory: " + (FullHistory ? "true" : "false") + "\n";
out += indentation +
" SubmoduleInitType: " +
SubmoduleInitTypeToString(CurrentSubmoduleInitType) +
"\n";
return out;
}
inline bool Equals(const GitSource& other) const
{
return URL == other.URL &&
Branch == other.Branch &&
FullHistory == other.FullHistory &&
CurrentSubmoduleInitType == other.CurrentSubmoduleInitType;
}
};
}
}
#endif