Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/integration test pipeline #924

Merged
merged 2 commits into from
Dec 4, 2023
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
212 changes: 212 additions & 0 deletions test/integration/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
{
"source-project": "Agile-Demo",
"target-project": "AzureDevOps-Jira-Migrator-Smoke-Tests",
"query": "project = \"AGILEDEMO\" ORDER BY created DESC",
"using-jira-cloud": true,
"workspace": "__workspace__",
"epic-link-field": "Epic Link",
"sprint-field": "Sprint",
"download-options": 7,
"batch-size": 20,
"log-level": "Info",
"attachment-folder": "Attachments",
"user-mapping-file": "users.txt",
"base-area-path": "Migrated",
"base-iteration-path": "Migrated",
"ignore-failed-links": true,
"process-template": "Agile",
"link-map": {
"link": [
{
"source": "Epic",
"target": "System.LinkTypes.Hierarchy-Reverse"
},
{
"source": "Parent",
"target": "System.LinkTypes.Hierarchy-Reverse"
},
{
"source": "Child",
"target": "System.LinkTypes.Hierarchy-Forward"
},
{
"source": "Relates",
"target": "System.LinkTypes.Related"
},
{
"source": "Duplicate",
"target": "System.LinkTypes.Duplicate-Forward"
}
]
},
"type-map": {
"type": [
{
"source": "Epic",
"target": "Epic"
},
{
"source": "Story",
"target": "Feature"
},
{
"source": "Bug",
"target": "Bug"
},
{
"source": "Task",
"target": "Task"
},
{
"source": "Sub-task",
"target": "Task"
}
]
},
"field-map": {
"field": [
{
"source": "summary",
"target": "System.Title",
"mapper": "MapTitle"
},
{
"source": "assignee",
"target": "System.AssignedTo",
"mapper": "MapUser"
},
{
"source": "description",
"target": "System.Description",
"mapper": "MapRendered"
},
{
"source": "priority",
"target": "Microsoft.VSTS.Common.Priority",
"mapping": {
"values": [
{
"source": "Highest",
"target": "1"
},
{
"source": "High",
"target": "2"
},
{
"source": "Medium",
"target": "3"
},
{
"source": "Low",
"target": "3"
},
{
"source": "Lowest",
"target": "4"
}
]
}
},
{
"source": "labels",
"target": "System.Tags",
"mapper": "MapTags"
},
{
"source": "comment",
"target": "System.History",
"mapper": "MapRendered"
},
{
"source": "status",
"target": "System.State",
"for": "Feature,Epic,User Story,Bug",
"mapping": {
"values": [
{
"source": "To Do",
"target": "New"
},
{
"source": "In Progress",
"target": "Active"
},
{
"source": "Done",
"target": "Resolved"
},
{
"source": "Done",
"target": "Closed"
},
{
"source": "Removed",
"target": "Removed"
}
]
}
},
{
"source": "status",
"target": "System.State",
"for": "Task",
"mapping": {
"values": [
{
"source": "To Do",
"target": "New"
},
{
"source": "In Progress",
"target": "Active"
},
{
"source": "Done",
"target": "Closed"
},
{
"source": "Removed",
"target": "Removed"
}
]
}
},
{
"source": "Story Points",
"source-type": "name",
"target": "Microsoft.VSTS.Scheduling.StoryPoints",
"not-for": "Task"
},
{
"source": "timeestimate",
"target": "Microsoft.VSTS.Scheduling.RemainingWork",
"mapper": "MapRemainingWork",
"for": "Bug,Task"
},
{
"source": "description",
"target": "Microsoft.VSTS.TCM.ReproSteps",
"for": "Bug"
},
{
"source": "environment",
"source-type": "name",
"target": "Microsoft.VSTS.TCM.SystemInfo",
"for": "Bug,Epic"
},
{
"source": "fixversions",
"source-type": "name",
"target": "Custom.FixVersion",
"for": "Bug,Feature"
},
{
"source": "alexander-custom-html",
"target": "Custom.CustomHtml",
"source-type": "name",
"mapper": "MapRendered"
}
]
}
}
93 changes: 93 additions & 0 deletions test/integration/delete-work-items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import sys
import requests
import base64

##########################
###### ADO REST API ######
##########################


### Wiql - Query By Wiql
# https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/wiql/query-by-wiql
# Params:
# - project_name: The friendly name or guid of the project
# - team_name: The guid or friendly name of the team (optional)
# - query: The wiql query.
def list_workitems_by_wiql(
PAT: str, organization_url: str, project_name: str, query: str = ""
):
headers = {
"Authorization": create_auth_header(PAT),
"Content-Type": "application/json",
}
body = '{"query": "' + query + '"}'

uri_api = "{0}/{1}/_apis/wit/wiql?api-version=6.0".format(
organization_url, project_name
)
response = requests.post(url=uri_api, headers=headers, data=body)
r = None
try:
r = response.json()
except:
print("Http error while sending to the enpoint: " + uri_api)
print(response)
print("body:" + body)
return r


### Work Items - Delete
# https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/work-items/delete
# Params:
# - project_name: The friendly name or guid of the project
# - id: ID of the work item
def delete_workitem(PAT: str, organization_url: str, project_name: str, id: str):
headers = {
"Authorization": create_auth_header(PAT),
"Content-Type": "application/json",
}
uri_api = "{0}/{1}/_apis/wit/workitems/{2}?$expand=All&api-version=6.0".format(
organization_url, project_name, id
)
response = requests.delete(url=uri_api, headers=headers)
return response.json()


def create_auth_header(PAT):
return "Basic " + str(base64.b64encode(bytes(":" + PAT, "ascii")), "ascii")


####################
###### CONFIG ######
####################

print("Argument List:", str(sys.argv))

ado_organization_url: str = sys.argv[1]
ado_project_name: str = sys.argv[2]
ado_api_token: str = sys.argv[3]

#####################
###### PROGRAM ######
#####################

# Set queries
ado_wiql_query: str = (
"SELECT [Id] FROM WorkItems WHERE [System.TeamProject] = '{0}'".format(
ado_project_name
)
)

# Get issues/work items
ado_work_items_json: list = list_workitems_by_wiql(
ado_api_token, ado_organization_url, ado_project_name, ado_wiql_query
)

original_wi_count: int = len(ado_work_items_json["workItems"])

for work_item in ado_work_items_json["workItems"]:
delete_workitem(
ado_api_token, ado_organization_url, ado_project_name, work_item["id"]
)

print("Deleted {0} work items from {1}".format(original_wi_count, ado_project_name))
61 changes: 61 additions & 0 deletions test/integration/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
trigger: none

pool:
vmimage: windows-2019

variables:
- group: jira-azuredevops-migrator-smoke-tests
- name: BuildPlatform
value: 'any cpu'
- name: BuildConfiguration
value: 'release'

steps:
- checkout: self

- task: PowerShell@2
displayName: 'Replace Migration workspace token in config'
inputs:
targetType: 'inline'
script: |
$file = "$(System.DefaultWorkingDirectory)\test\integration\config.json"
$str_find = "__workspace__"
$str_replace = "$(System.DefaultWorkingDirectory)\test\integration\jira-migrator-workspace"
$str_replace = $str_replace -replace "\\", "\\"
((Get-Content -path $file -Raw) -replace $str_find, $str_replace) | Set-Content -Path $file
cat $file

- task: NuGetCommand@2
displayName: 'NuGet restore'
inputs:
restoreSolution: '**\*.sln'

- task: VSBuild@1
displayName: 'Build solution WorkItemMigrator'
inputs:
solution: $(System.DefaultWorkingDirectory)\src\WorkItemMigrator\WorkItemMigrator.sln
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'

- script: pip install requests python-dateutil
displayName: pip install

- task: PythonScript@0
displayName: Delete work items on target org, PythonScript
inputs:
scriptSource: 'filePath'
scriptPath: '$(System.DefaultWorkingDirectory)\test\integration\delete-work-items.py'
arguments: '$(AdoOrganizationUrl) $(AdoProjectName) $(AdoApiToken)'

- script: $(System.DefaultWorkingDirectory)\src\WorkItemMigrator\JiraExport\bin\$(BuildConfiguration)\jira-export.exe -u $(JiraUser) -p $(JiraApiToken) --url $(JiraUrl) --config $(System.DefaultWorkingDirectory)\test\integration\config.json --force
displayName: jira-export.exe

- script: $(System.DefaultWorkingDirectory)\src\WorkItemMigrator\WorkItemImport\bin\$(BuildConfiguration)\wi-import.exe --token $(AdoApiToken) --url $(AdoOrganizationUrl) --config $(System.DefaultWorkingDirectory)\test\integration\config.json --force
displayName: wi-import.exe

- task: PythonScript@0
displayName: Smoke tests, PythonScript
inputs:
scriptSource: 'filePath'
scriptPath: '$(System.DefaultWorkingDirectory)\test\integration\smoke-tests.py'
arguments: '$(AdoOrganizationUrl) $(AdoProjectName) $(AdoApiToken) $(JiraUrl) $(JiraUser) $(JiraApiToken) $(JiraProject) $(System.DefaultWorkingDirectory)\test\integration\jira-migrator-workspace\users.txt'
Loading
Loading