Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions src/ADOGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
Environment.Exit(0);

} while (true);
return 0;

Check warning on line 102 in src/ADOGenerator/Program.cs

View workflow job for this annotation

GitHub Actions / build

Unreachable code detected

Check warning on line 102 in src/ADOGenerator/Program.cs

View workflow job for this annotation

GitHub Actions / build

Unreachable code detected

void HandleTemplateAndArtifactsUpdate(string template, string id, Project model, string currentPath)
{
Expand Down Expand Up @@ -218,12 +218,12 @@

var templateFolder = string.Empty;
var confirmedExtension = false;
if (!TryGetTemplateDetails(groupwiseTemplates, selectedTemplateName, out templateFolder, out confirmedExtension, id))
if (!TryGetTemplateDetails(groupwiseTemplates, selectedTemplateName, out templateFolder, id))
{
return;
}

ValidateExtensions(templateFolder, id);
confirmedExtension = ValidateExtensions(templateFolder, id);

var (accessToken, organizationName, authScheme) = AuthenticateUser(init, id);
if (string.IsNullOrWhiteSpace(accessToken) || string.IsNullOrWhiteSpace(organizationName)) return;
Expand Down Expand Up @@ -541,11 +541,9 @@
} while (string.IsNullOrWhiteSpace(projectName));
return projectName;
}

bool TryGetTemplateDetails(JToken groupwiseTemplates, string selectedTemplateName, out string templateFolder, out bool confirmedExtension, string id)
bool TryGetTemplateDetails(JToken groupwiseTemplates, string selectedTemplateName, out string templateFolder, string id)
{
templateFolder = string.Empty;
confirmedExtension = false;

foreach (var group in groupwiseTemplates)
{
Expand All @@ -556,20 +554,15 @@
{
if (template["Name"]?.ToString().Equals(selectedTemplateName, StringComparison.OrdinalIgnoreCase) != true)
continue;
else
templateFolder = template["TemplateFolder"]?.ToString();
var templateFolderPath = Path.Combine(Directory.GetCurrentDirectory(), "Templates", templateFolder);
if (!Directory.Exists(templateFolderPath))
{
templateFolder = template["TemplateFolder"]?.ToString();
var templateFolderPath = Path.Combine(Directory.GetCurrentDirectory(), "Templates", templateFolder);

if (!Directory.Exists(templateFolderPath))
{
id.ErrorId().AddMessage($"Template '{selectedTemplateName}' is not found.");
return false;
}
id.AddMessage($"Template '{selectedTemplateName}' is present.");
return true;
id.ErrorId().AddMessage($"Template '{selectedTemplateName}' is not found.");
return false;
}

id.AddMessage($"Template '{selectedTemplateName}' is present.");
return true;
}
}
return false;
Expand Down
103 changes: 85 additions & 18 deletions src/ADOGenerator/Services/ProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public bool CreateProjectEnvironment(Project model)
List<RestAPI.WorkItemAndTracking.WIMapData> wiMapping = new List<RestAPI.WorkItemAndTracking.WIMapData>();
//AccountMembers.Account accountMembers = new AccountMembers.Account();
model.accountUsersForWi = new List<string>();
model.Parameters = new Dictionary<string, string>();
websiteUrl = model.websiteUrl;
projectName = model.ProjectName;
adoAuthScheme = model.adoAuthScheme;
Expand Down Expand Up @@ -416,7 +417,7 @@ public bool CreateProjectEnvironment(Project model)
//get project id after successfull in VSTS
model.Environment.ProjectId = objProject.GetProjectIdByName(model.ProjectName);
model.Environment.ProjectName = model.ProjectName;

GetServiceEndPointCredentials(model);
// Fork Repo
//if (model.GitHubFork && model.GitHubToken != null)
//{
Expand Down Expand Up @@ -627,7 +628,7 @@ public bool CreateProjectEnvironment(Project model)
string repositoryToDelete = objRepository.GetRepositoryToDelete(model.ProjectName);
bool isDeleted = objRepository.DeleteRepository(repositoryToDelete);
}

isDefaultRepoTodetele = true;
#endregion

//Create Pull request
Expand Down Expand Up @@ -842,6 +843,64 @@ public bool CreateProjectEnvironment(Project model)
return true;
}

private void GetServiceEndPointCredentials(Project model)
{
try
{
Init init = new Init();
if (model.TemplateName.ToLower() == "bikesharing360")
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("Please enter the User ID : ");
Console.ResetColor();
string bikeSharing360username = Console.ReadLine();
model.Parameters["BikeSharing360UserID"] = bikeSharing360username;
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("Please enter the Password : ");
Console.ResetColor();
string bikeSharing360password = init.ReadSecret();
model.Parameters["BikeSharing360Password"] = bikeSharing360password;
}
else if (model.TemplateName.ToLower() == "contososhuttle" || model.TemplateName.ToLower() == "contososhuttle2")
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("Please enter the User ID : ");
Console.ResetColor();
string contosousername = Console.ReadLine();
model.Parameters["ContosoUserID"] = contosousername;
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("Please enter the Password : ");
Console.ResetColor();
string contosopassword = init.ReadSecret();
model.Parameters["ContosoPassword"] = contosopassword;
}
else if (model.TemplateName.ToLower() == "sonarqube")
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("Please enter the SonarQube DNS : ");
Console.ResetColor();
string sonarQubeDNS = Console.ReadLine();
model.SonarQubeDNS = sonarQubeDNS;
}
else if (model.TemplateName.ToLower() == "octopus")
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("Please enter the Octopus URL : ");
Console.ResetColor();
string octopusURL = Console.ReadLine();
model.Parameters["OctopusURL"] = octopusURL;
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("Please enter the API Key : ");
Console.ResetColor();
string apiKey = init.ReadSecret();
model.Parameters["APIkey"] = apiKey;
}
}
catch (Exception ex)
{
model.id.ErrorId().AddMessage("Error while getting service endpoint credentials: " + ex.Message);
}
}

bool CreateBranchPolicy(Project model, ADOConfiguration buildConfig)
{
Expand Down Expand Up @@ -1328,13 +1387,13 @@ bool UpdateBoardColumn(Project model, string BoardColumnsJSON, ADOConfiguration
}
else if (!(string.IsNullOrEmpty(objBoard.LastFailureMessage)))
{
id.ErrorId().AddMessage("Error while updating board column " + objBoard.LastFailureMessage + Environment.NewLine);
id.ErrorId().AddMessage("Error while updating board column for board type : " + BoardType + objBoard.LastFailureMessage + Environment.NewLine);
}
}
catch (Exception ex)
{
// logger.Info(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + "\t" + ex.Message + "\t" + "\n" + ex.StackTrace + "\n");
id.ErrorId().AddMessage("Error while updating board column " + ex.Message);
id.ErrorId().AddMessage("Error while updating board column for board type : " + BoardType + ex.Message);
}
return result;
}
Expand All @@ -1356,13 +1415,13 @@ void UpdateCardFields(Project model, string json, ADOConfiguration _configuratio

if (!string.IsNullOrEmpty(objCards.LastFailureMessage))
{
id.ErrorId().AddMessage("Error while updating card fields: " + objCards.LastFailureMessage + Environment.NewLine);
id.ErrorId().AddMessage("Error while updating card fields for board type : " + boardType + objCards.LastFailureMessage + Environment.NewLine);
}
}
catch (Exception ex)
{
// logger.Info(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + "\t" + ex.Message + "\t" + "\n" + ex.StackTrace + "\n");
id.ErrorId().AddMessage("Error while updating card fields: " + ex.Message);
id.ErrorId().AddMessage("Error while updating card fields for board type : "+ boardType + ex.Message);

}

Expand All @@ -1384,13 +1443,13 @@ void UpdateCardStyles(Project model, string json, ADOConfiguration _configuratio

if (!string.IsNullOrEmpty(objCards.LastFailureMessage))
{
id.ErrorId().AddMessage("Error while updating card styles: " + objCards.LastFailureMessage + Environment.NewLine);
id.ErrorId().AddMessage("Error while updating card styles for board type : " + boardType + objCards.LastFailureMessage + Environment.NewLine);
}
}
catch (Exception ex)
{
// logger.Info(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + "\t" + ex.Message + "\t" + "\n" + ex.StackTrace + "\n");
id.ErrorId().AddMessage("Error while updating card styles: " + ex.Message);
id.ErrorId().AddMessage("Error while updating card styles for board type : " + boardType + ex.Message);
}

}
Expand Down Expand Up @@ -1651,6 +1710,14 @@ void ImportSourceCode(Project model, string sourceCodeJSON, ADOConfiguration _re
if (model.ProjectName.ToLower() == repositoryName.ToLower())
{
repositoryDetail = objRepository.GetDefaultRepository(model.ProjectName);
if (repositoryDetail.All(string.IsNullOrEmpty))
{
repositoryDetail = objRepository.CreateRepository(model.ProjectName, model.Environment.ProjectId);
}
else
{
isDefaultRepoTodetele = false;
}
}
else
{
Expand Down Expand Up @@ -1681,9 +1748,9 @@ void ImportSourceCode(Project model, string sourceCodeJSON, ADOConfiguration _re
model.Environment.reposImported.Add(repositoryDetail[0], copySourceCode);
}

if (!(string.IsNullOrEmpty(objRepository.LastFailureMessage)))
if (!(string.IsNullOrEmpty(objRepositorySourceCode.LastFailureMessage)))
{
id.ErrorId().AddMessage("Error while importing source code: " + objRepository.LastFailureMessage + Environment.NewLine);
id.ErrorId().AddMessage("Error while importing source code: " + objRepositorySourceCode.LastFailureMessage + Environment.NewLine);
}
}

Expand Down Expand Up @@ -1831,26 +1898,26 @@ void CreateServiceEndPoint(Project model, List<string> jsonPaths, ADOConfigurati
jsonCreateService = jsonCreateService.Replace("$username$", username).Replace("$password$", password) // Replaces user name and password with app setting username and password if require[to import soure code to Azure Repos]
.Replace("$GitUserName$", gitUserName).Replace("$GitUserPassword$", gitUserPassword); // Replaces GitUser name and passwords with Demo gen username and password [Just to point build def to respective repo]
}
if (model.SelectedTemplate.ToLower() == "bikesharing360")
if (model.TemplateName.ToLower() == "bikesharing360")
{
string bikeSharing360username = _configuration["AppSettings:UserID"];
string bikeSharing360password = _configuration["AppSettings:BikeSharing360Password"];
string bikeSharing360username = model.Parameters["BikeSharing360UserID"];
string bikeSharing360password = model.Parameters["BikeSharing360Password"];
jsonCreateService = jsonCreateService.Replace("$BikeSharing360username$", bikeSharing360username).Replace("$BikeSharing360password$", bikeSharing360password);
}
else if (model.SelectedTemplate.ToLower() == "contososhuttle" || model.SelectedTemplate.ToLower() == "contososhuttle2")
else if (model.TemplateName.ToLower() == "contososhuttle" || model.TemplateName.ToLower() == "contososhuttle2")
{
string contosousername = _configuration["AppSettings:ContosoUserID"];
string contosopassword = _configuration["AppSettings:ContosoPassword"];
string contosousername = model.Parameters["ContosoUserID"];
string contosopassword = model.Parameters["ContosoPassword"];
jsonCreateService = jsonCreateService.Replace("$ContosoUserID$", contosousername).Replace("$ContosoPassword$", contosopassword);
}
else if (model.SelectedTemplate.ToLower() == "sonarqube")
else if (model.TemplateName.ToLower() == "sonarqube")
{
if (!string.IsNullOrEmpty(model.SonarQubeDNS))
{
jsonCreateService = jsonCreateService.Replace("$URL$", model.SonarQubeDNS);
}
}
else if (model.SelectedTemplate.ToLower() == "octopus")
else if (model.TemplateName.ToLower() == "octopus")
{
var url = model.Parameters["OctopusURL"];
var apiKey = model.Parameters["APIkey"];
Expand Down
8 changes: 4 additions & 4 deletions src/ADOGenerator/Templates/DL-AKS/ImportSourceCode/AKS.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"parameters":
{
"gitSource":
{
"url": "https://vstsdemodata.visualstudio.com/_git/AKS"
},
"gitSource":
{
"url": "https://dev.azure.com/vstsdemodata/AKS/_git/AKS"
},
"serviceEndpointId": "$AKS-code$",
"deleteServiceEndpointAfterImportIsDone": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"name": "AKS-code",
"type": "git",
"url": "https://vstsdemodata.visualstudio.com/_git/AKS",
"url": "https://dev.azure.com/vstsdemodata/AKS/_git/AKS",
"authorization": {
"scheme": "UsernamePassword",
"parameters": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"parameters": {
"gitSource": {
"url": "https://vstsdemodata.visualstudio.com/Ansible/_git/SmartHotel360-CouponManagement"
"url": "https://dev.azure.com/vstsdemodata/Ansible/_git/SmartHotel360-CouponManagement"
},
"serviceEndpointId": "$Ansible-code$",
"deleteServiceEndpointAfterImportIsDone": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"name": "Ansible-code",
"type": "git",
"url": "https://vstsdemodata.visualstudio.com/Ansible/_git/SmartHotel360-CouponManagement",
"url": "https://dev.azure.com/vstsdemodata/Ansible/_git/SmartHotel360-CouponManagement",
"authorization": {
"scheme": "UsernamePassword",
"parameters": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"parameters": {
"gitSource": {
"url": "https://dev.azure.com/vstsdemodata/_git/AzureFunctions"
"parameters":
{
"gitSource":
{
"url": "https://dev.azure.com/vstsdemodata/AzureFunctions/_git/AzureFunctions"
},
"serviceEndpointId": "$AzureFunctions-code$",
"deleteServiceEndpointAfterImportIsDone": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"name": "AzureFunctions-code",
"type": "git",
"url": "https://dev.azure.com/vstsdemodata/_git/AzureFunctions",
"url": "https://dev.azure.com/vstsdemodata/AzureFunctions/_git/AzureFunctions",
"authorization": {
"scheme": "UsernamePassword",
"parameters": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"parameters": {
"gitSource": {
"url": "https://vstsdemodata.visualstudio.com/Deployment%20Groups/_git/DeploymentGroup"
"url": "https://dev.azure.com/vstsdemodata/Deployment%20Groups/_git/DeploymentGroup"
},
"serviceEndpointId": "$DeploymentGroup-code$",
"deleteServiceEndpointAfterImportIsDone": true
Expand Down
10 changes: 5 additions & 5 deletions src/ADOGenerator/Templates/DL-DeploymentGroups/Iterations.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@
"name": "Iteration 1",
"structureType": "iteration",
"hasChildren": false,
"url": "https://vstsdemodata.visualstudio.com/851b582e-a87d-46e1-ba2c-023e9daedda7/_apis/wit/classificationNodes/Iterations/Iteration%201",
"url": "https://dev.azure.com/vstsdemodata/851b582e-a87d-46e1-ba2c-023e9daedda7/_apis/wit/classificationNodes/Iterations/Iteration%201",
"children": null
},
{
"id": 88,
"name": "Iteration 2",
"structureType": "iteration",
"hasChildren": false,
"url": "https://vstsdemodata.visualstudio.com/851b582e-a87d-46e1-ba2c-023e9daedda7/_apis/wit/classificationNodes/Iterations/Iteration%202",
"url": "https://dev.azure.com/vstsdemodata/851b582e-a87d-46e1-ba2c-023e9daedda7/_apis/wit/classificationNodes/Iterations/Iteration%202",
"children": null
},
{
"id": 89,
"name": "Iteration 3",
"structureType": "iteration",
"hasChildren": false,
"url": "https://vstsdemodata.visualstudio.com/851b582e-a87d-46e1-ba2c-023e9daedda7/_apis/wit/classificationNodes/Iterations/Iteration%203",
"url": "https://dev.azure.com/vstsdemodata/851b582e-a87d-46e1-ba2c-023e9daedda7/_apis/wit/classificationNodes/Iterations/Iteration%203",
"children": null
}
],
"_links": {
"self": {
"href": "https://vstsdemodata.visualstudio.com/851b582e-a87d-46e1-ba2c-023e9daedda7/_apis/wit/classificationNodes/Iterations"
"href": "https://dev.azure.com/vstsdemodata/851b582e-a87d-46e1-ba2c-023e9daedda7/_apis/wit/classificationNodes/Iterations"
}
},
"url": "https://vstsdemodata.visualstudio.com/851b582e-a87d-46e1-ba2c-023e9daedda7/_apis/wit/classificationNodes/Iterations",
"url": "https://dev.azure.com/vstsdemodata/851b582e-a87d-46e1-ba2c-023e9daedda7/_apis/wit/classificationNodes/Iterations",
"HttpStatusCode": 200,
"Message": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"data": {},
"name": "DeploymentGroup-code",
"type": "git",
"url":"https://vstsdemodata.visualstudio.com/Deployment%20Groups/_git/DeploymentGroup",
"url":"https://dev.azure.com/vstsdemodata/Deployment%20Groups/_git/DeploymentGroup",
"authorization": {
"scheme": "UsernamePassword",
"parameters": {
Expand Down
Loading
Loading