Skip to content

Instantly share code, notes, and snippets.

@IlyaFinkelshteyn
Last active May 5, 2020 15:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IlyaFinkelshteyn/aea8408cc7c7c836431dab8f898d09a1 to your computer and use it in GitHub Desktop.
Save IlyaFinkelshteyn/aea8408cc7c7c836431dab8f898d09a1 to your computer and use it in GitHub Desktop.
$token = '<API_TOKEN>' # account-level API token
$headers = @{
"Authorization" = "Bearer $token"
"Content-type" = "application/json"
}
# create new project
$body = @{
repositoryProvider="gitHub"
repositoryName="<githib_user_name>/<github_repo_name>"
}
$body = $body | ConvertTo-Json
#use 'https://ci.appveyor.com/api/account/<appveyor_account_name>/projects' endpount is using v2 'all accounts' API token
$newProject = Invoke-RestMethod -Uri 'https://ci.appveyor.com/api/projects' -Headers $headers -Body $body -Method POST
# read existing project config
# note: by default <appveyor_account_name> is the same as <githib_user_name> and <appveyor_project_name> is the same as <github_repo_name>
$s = Invoke-RestMethod -Uri 'https://ci.appveyor.com/api/projects/<appveyor_account_name>/<appveyor_project_name>/settings' -Headers $headers -Method Get
# update config with new project data
$s.settings.projectId = $newProject.projectId
$s.settings.slug = ($s.settings.slug + "-new")
# optionally update project name
$s.settings.name = ($newProject.name + "-new")
#update new project
Invoke-RestMethod -Uri 'https://ci.appveyor.com/api/projects' -Headers $headers -Body ($s.settings | ConvertTo-Json -Depth 10) -Method Put
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment