More edits
This commit is contained in:
@@ -9,6 +9,7 @@ require "tmpdir"
|
||||
|
||||
options = {
|
||||
assets_file: "azure_devops.tgz",
|
||||
pipeline_assets_dir: "pipelines",
|
||||
root_dir: File.join(ENV["CODESPACE_VSCODE_FOLDER"], "azure_devops/bootstrap"),
|
||||
forecast_source_file: "jobs.json"
|
||||
}
|
||||
@@ -75,57 +76,57 @@ def create_repository(options)
|
||||
root_dir = options[:root_dir]
|
||||
assets_file = options[:assets_file]
|
||||
|
||||
Dir.mktmpdir do |tmp_dir|
|
||||
puts "Extracting assets..."
|
||||
_, _, st = Open3.capture3("tar", "-xzf", File.join(root_dir, assets_file), "-C", tmp_dir)
|
||||
abort unless st.exitstatus == 0
|
||||
|
||||
uri = URI("https://dev.azure.com/#{organization}/#{project}/_apis/git/repositories/#{repository}/pushes?api-version=7.1-preview.2")
|
||||
puts "Creating repository #{repository}..."
|
||||
|
||||
root = Pathname.new(root_dir)
|
||||
repository_to_create = {
|
||||
refUpdates: [{
|
||||
name: "refs/heads/main",
|
||||
oldObjectId: "0000000000000000000000000000000000000000"
|
||||
}],
|
||||
commits: [{
|
||||
comment: "Initial commit.",
|
||||
changes: Dir[File.join(tmp_dir, "**/*")].reject {|f| File.directory?(f) }.map do |entry|
|
||||
{
|
||||
changeType: "add",
|
||||
item: {
|
||||
path: File.join("/", Pathname.new(entry).relative_path_from(tmp_dir).to_s)
|
||||
},
|
||||
newContent: {
|
||||
content: File.read(entry),
|
||||
contentType: "rawText"
|
||||
}
|
||||
tmp_dir = Dir.mktmpdir
|
||||
puts "Extracting assets..."
|
||||
_, _, st = Open3.capture3("tar", "-xzf", File.join(root_dir, assets_file), "-C", tmp_dir)
|
||||
abort unless st.exitstatus == 0
|
||||
|
||||
uri = URI("https://dev.azure.com/#{organization}/#{project}/_apis/git/repositories/#{repository}/pushes?api-version=7.1-preview.2")
|
||||
puts "Creating repository #{repository}..."
|
||||
|
||||
root = Pathname.new(root_dir)
|
||||
repository_to_create = {
|
||||
refUpdates: [{
|
||||
name: "refs/heads/main",
|
||||
oldObjectId: "0000000000000000000000000000000000000000"
|
||||
}],
|
||||
commits: [{
|
||||
comment: "Initial commit.",
|
||||
changes: Dir[File.join(tmp_dir, "**/*")].reject {|f| File.directory?(f) }.map do |entry|
|
||||
{
|
||||
changeType: "add",
|
||||
item: {
|
||||
path: File.join("/", Pathname.new(entry).relative_path_from(tmp_dir).to_s)
|
||||
},
|
||||
newContent: {
|
||||
content: File.read(entry),
|
||||
contentType: "rawText"
|
||||
}
|
||||
end.flatten
|
||||
}]
|
||||
}
|
||||
}
|
||||
end.flatten
|
||||
}]
|
||||
}
|
||||
|
||||
post_request(uri, repository_to_create, access_token) do |response|
|
||||
raise "Error creating repository (#{response.code}:#{response.message})" unless response.code.start_with?("20")
|
||||
end
|
||||
result = post_request(uri, repository_to_create, access_token) do |response|
|
||||
raise "Error creating repository (#{response.code}:#{response.message})" unless response.code.start_with?("20")
|
||||
end
|
||||
|
||||
[result, tmp_dir]
|
||||
end
|
||||
|
||||
def create_yaml_pipelines(options, repository)
|
||||
def create_yaml_pipelines(options, repository, tmp_dir)
|
||||
organization = options[:organization]
|
||||
project = options[:project]
|
||||
repository_name = repository.dig("repository", "name")
|
||||
repository_id = repository.dig("repository", "id")
|
||||
access_token = options[:access_token]
|
||||
root_dir = options[:root_dir]
|
||||
pipeline_assets_dir = options[:pipeline_assets_dir]
|
||||
|
||||
puts "Creating yaml pipelines..."
|
||||
|
||||
uri = URI("https://dev.azure.com/#{organization}/#{project}/_apis/pipelines?api-version=6.0-preview.1")
|
||||
root = Pathname.new(root_dir)
|
||||
Dir[File.join(root_dir, pipeline_assets_dir, "yml", "*")].each do |entry|
|
||||
root = Pathname.new(tmp_dir)
|
||||
Dir[File.join(tmp_dir, pipeline_assets_dir, "yml", "*")].each do |entry|
|
||||
puts "Creating pipeline #{entry}..."
|
||||
|
||||
pipeline_to_create = {
|
||||
@@ -175,20 +176,20 @@ def create_classic_pipelines(options, repository)
|
||||
end
|
||||
end
|
||||
|
||||
def update_forecast_source_file(options)
|
||||
def update_forecast_source_file(options, tmp_dir)
|
||||
puts "Updating forecast data"
|
||||
root_dir = options[:root_dir]
|
||||
jobs_data_file = options[:forecast_source_file]
|
||||
jobs_data = File.read(File.join(root_dir, jobs_data_file))
|
||||
jobs_data = File.read(File.join(tmp_dir, jobs_data_file))
|
||||
today = Date.today.strftime("%Y-%m-%d")
|
||||
jobs_data.gsub!(/20[0-2][0-9]-[0-1][0-9]-[0-3][0-9]/, today)
|
||||
File.write(options[:forecast_source_file], jobs_data)
|
||||
File.write(File.join(root_dir, jobs_data_file), jobs_data)
|
||||
end
|
||||
|
||||
# create_project(options)
|
||||
repository = create_repository(options)
|
||||
create_yaml_pipelines(options, repository)
|
||||
create_project(options)
|
||||
repository, tmp_dir = create_repository(options)
|
||||
create_yaml_pipelines(options, repository, tmp_dir)
|
||||
create_classic_pipelines(options, repository)
|
||||
update_forecast_source_file(options)
|
||||
update_forecast_source_file(options, tmp_dir)
|
||||
|
||||
puts "Success!"
|
||||
|
||||
Reference in New Issue
Block a user