copy stories from old circle #15

Closed
opened 2024-03-20 09:25:28 +00:00 by despiegk · 2 comments
Owner
https://git.ourworld.tf/tfcoop/circle_prodmgmt_grid/issues
sabrinasadik was assigned by despiegk 2024-03-20 09:26:01 +00:00
sashaastiadi was assigned by despiegk 2024-03-20 09:26:09 +00:00
Owner

done

done
Owner

done using python script

import requests

Define Gitea instance URLs

source_gitea_url = 'https://git.ourworld.tf/api/v1'
target_gitea_url = 'https://git.ourworld.tf/api/v1'

Define authentication tokens

source_token = 'token'
target_token = 'token'

Define organization and repository names

source_org = 'tfcoop'
source_repo = 'circle_prodmgmt_grid'

target_org = 'tfgrid'
target_repo = 'circle_engineering'

Define issue number to move

issue_number = #

def fetch_issue_details(org, repo, issue_number):
response = requests.get(f'{source_gitea_url}/repos/{org}/{repo}/issues/{issue_number}', headers={'Authorization': f'token {source_token}'})
if response.status_code == 200:
return response.json()
else:
print(f"Failed to fetch issue details from {org}/{repo} for issue #{issue_number}.")
return None

def fetch_comments(org, repo, issue_number):
response = requests.get(f'{source_gitea_url}/repos/{org}/{repo}/issues/{issue_number}/comments', headers={'Authorization': f'token {source_token}'})
if response.status_code == 200:
return response.json()
else:
print(f"Failed to fetch comments for issue #{issue_number} in {org}/{repo}.")
return None

def create_issue(org, repo, issue_details):
data = {
'title': issue_details['title'],
'body': issue_details['body']
# Add more fields as needed
}
response = requests.post(f'{target_gitea_url}/repos/{org}/{repo}/issues', json=data, headers={'Authorization': f'token {target_token}'})
if response.status_code == 201:
return response.json()['number']
else:
print(f"Failed to create issue in {org}/{repo}.")
return None

def create_comment(org, repo, issue_number, comment_body):
data = {
'body': comment_body
}
response = requests.post(f'{target_gitea_url}/repos/{org}/{repo}/issues/{issue_number}/comments', json=data, headers={'Authorization': f'token {target_token}'})
if response.status_code == 201:
return True
else:
print(f"Failed to create comment on issue #{issue_number} in {org}/{repo}.")
return False

def main():
# Fetch issue details from source repository
issue_details = fetch_issue_details(source_org, source_repo, issue_number)
if issue_details:
# Create issue in target repository
new_issue_number = create_issue(target_org, target_repo, issue_details)
if new_issue_number:
print(f"Issue #{issue_number} moved successfully to {target_org}/{target_repo} as issue #{new_issue_number}.")
# Fetch comments from source issue
comments = fetch_comments(source_org, source_repo, issue_number)
if comments:
# Post comments to new issue
for comment in comments:
success = create_comment(target_org, target_repo, new_issue_number, comment['body'])
if success:
print(f"Comment on issue #{issue_number} copied successfully.")
else:
print(f"Failed to copy comment on issue #{issue_number}.")
else:
print(f"Failed to move issue #{issue_number} to {target_org}/{target_repo}.")
else:
print(f"Failed to move issue #{issue_number} from {source_org}/{source_repo}.")

if name == "main":
main()

done using python script import requests # Define Gitea instance URLs source_gitea_url = 'https://git.ourworld.tf/api/v1' target_gitea_url = 'https://git.ourworld.tf/api/v1' # Define authentication tokens source_token = 'token' target_token = 'token' # Define organization and repository names source_org = 'tfcoop' source_repo = 'circle_prodmgmt_grid' target_org = 'tfgrid' target_repo = 'circle_engineering' # Define issue number to move issue_number = # def fetch_issue_details(org, repo, issue_number): response = requests.get(f'{source_gitea_url}/repos/{org}/{repo}/issues/{issue_number}', headers={'Authorization': f'token {source_token}'}) if response.status_code == 200: return response.json() else: print(f"Failed to fetch issue details from {org}/{repo} for issue #{issue_number}.") return None def fetch_comments(org, repo, issue_number): response = requests.get(f'{source_gitea_url}/repos/{org}/{repo}/issues/{issue_number}/comments', headers={'Authorization': f'token {source_token}'}) if response.status_code == 200: return response.json() else: print(f"Failed to fetch comments for issue #{issue_number} in {org}/{repo}.") return None def create_issue(org, repo, issue_details): data = { 'title': issue_details['title'], 'body': issue_details['body'] # Add more fields as needed } response = requests.post(f'{target_gitea_url}/repos/{org}/{repo}/issues', json=data, headers={'Authorization': f'token {target_token}'}) if response.status_code == 201: return response.json()['number'] else: print(f"Failed to create issue in {org}/{repo}.") return None def create_comment(org, repo, issue_number, comment_body): data = { 'body': comment_body } response = requests.post(f'{target_gitea_url}/repos/{org}/{repo}/issues/{issue_number}/comments', json=data, headers={'Authorization': f'token {target_token}'}) if response.status_code == 201: return True else: print(f"Failed to create comment on issue #{issue_number} in {org}/{repo}.") return False def main(): # Fetch issue details from source repository issue_details = fetch_issue_details(source_org, source_repo, issue_number) if issue_details: # Create issue in target repository new_issue_number = create_issue(target_org, target_repo, issue_details) if new_issue_number: print(f"Issue #{issue_number} moved successfully to {target_org}/{target_repo} as issue #{new_issue_number}.") # Fetch comments from source issue comments = fetch_comments(source_org, source_repo, issue_number) if comments: # Post comments to new issue for comment in comments: success = create_comment(target_org, target_repo, new_issue_number, comment['body']) if success: print(f"Comment on issue #{issue_number} copied successfully.") else: print(f"Failed to copy comment on issue #{issue_number}.") else: print(f"Failed to move issue #{issue_number} to {target_org}/{target_repo}.") else: print(f"Failed to move issue #{issue_number} from {source_org}/{source_repo}.") if __name__ == "__main__": main()
Sign in to join this conversation.
No Milestone
No project
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: tfgrid/circle_engineering#15
No description provided.