1
0

taiga_wiki_push.py 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. import requests
  2. import urllib3
  3. import os
  4. urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
  5. base_url = 'https://192.168.130.161/taiga/api/v1'
  6. auth_url = f'{base_url}/auth'
  7. auth = requests.post(auth_url, json={'type': 'normal', 'username': 'FrancoisLange', 'password': 'BTSai123'}, verify=False).json()
  8. headers = {'Authorization': f'Bearer {auth["auth_token"]}', 'Content-Type': 'application/json'}
  9. proj_id = 21
  10. def push_wiki(slug, md_path):
  11. with open(md_path, 'r') as f:
  12. content = f.read()
  13. res = requests.get(f'{base_url}/wiki?project={proj_id}&slug={slug}', headers=headers, verify=False).json()
  14. if len(res) > 0:
  15. wiki_id = res[0]['id']
  16. version = res[0]['version']
  17. payload = {'content': content, 'version': version}
  18. r = requests.put(f'{base_url}/wiki/{wiki_id}', json=payload, headers=headers, verify=False)
  19. print(f'Updated {slug}: {r.status_code}')
  20. else:
  21. payload = {'project': proj_id, 'slug': slug, 'content': content}
  22. r = requests.post(f'{base_url}/wiki', json=payload, headers=headers, verify=False)
  23. print(f'Created {slug}: {r.status_code}')
  24. # In Taiga, the home page of the wiki is usually 'home'
  25. push_wiki('home', 'docs/Scrum_Wiki.md')
  26. push_wiki('backup-procedure', 'docs/Backup_Procedure.md')
  27. push_wiki('wsl-deployment', 'docs/WSL_Deployment.md')
  28. push_wiki('test-cases-sprint8', 'docs/Test_Cases_Sprint8.md')