Skip to content

Instantly share code, notes, and snippets.

@IlyaFinkelshteyn
Last active February 12, 2019 21:27
Show Gist options
  • Save IlyaFinkelshteyn/8f195010434075074bfa4ee48e3fa347 to your computer and use it in GitHub Desktop.
Save IlyaFinkelshteyn/8f195010434075074bfa4ee48e3fa347 to your computer and use it in GitHub Desktop.
$env:API_URL = "https://ci.appveyor.com/api" # replace for AppVeyor Enterprise
$env:API_TOKEN = "<replace>" # from https://ci.appveyor.com/api-keys
$env:APPVEYOR_ACCOUNT_NAME = "<replace>" # from AppVeyor project URL
$env:APPVEYOR_PROJECT_SLUG_OLD = "<replace>" # from AppVeyor project URL
$env:APPVEYOR_PROJECT_SLUG_NEW = "<replace>" # Desired slug
$headers = @{
"Authorization" = "Bearer $env:API_TOKEN"
"Content-type" = "application/json"
}
$s = Invoke-RestMethod -Uri "$env:API_URL/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG_OLD/settings" -Headers $headers -Method Get
$s.settings.slug = $env:APPVEYOR_PROJECT_SLUG_NEW
Invoke-RestMethod -Uri "$env:API_URL/projects" -Headers $headers -Body ($s.settings | ConvertTo-Json -Depth 10) -Method Put
@dhermes
Copy link

dhermes commented Sep 24, 2018

A Python version:

import requests


API_URL = "https://ci.appveyor.com/api"  # replace for AppVeyor Enterprise
API_TOKEN = "<replace>"  # from https://ci.appveyor.com/api-keys
APPVEYOR_ACCOUNT_NAME = "<replace>"  # from AppVeyor project URL
APPVEYOR_PROJECT_SLUG_OLD = "<replace>"  # from AppVeyor project URL
APPVEYOR_PROJECT_SLUG_NEW = "<replace>"  # Desired slug

GET_URI = "{}/projects/{}/{}/settings".format(
    API_URL, APPVEYOR_ACCOUNT_NAME, APPVEYOR_PROJECT_SLUG_OLD
)
PUT_URI = "{}/projects".format(API_URL)


def main():
    headers = {
        "Authorization": "Bearer {}".format(API_TOKEN),
        "Content-type": "application/json",
    }

    response1 = requests.get(GET_URI, headers=headers)
    response1.raise_for_status()

    SETTINGS_PAYLOAD = response1.json()["settings"]
    SETTINGS_PAYLOAD["slug"] = APPVEYOR_PROJECT_SLUG_NEW
    response2 = requests.put(PUT_URI, json=SETTINGS_PAYLOAD, headers=headers)
    print(response2)


if __name__ == "__main__":
    main()

I also put it in a gist https://gist.github.com/dhermes/a4bc8adaf0048c4c69ddb671c61b10b2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment