taiga_wiki_push.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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, 'project': proj_id, 'slug': slug}
  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. if r.status_code != 200:
  21. print(r.text)
  22. else:
  23. payload = {'project': proj_id, 'slug': slug, 'content': content}
  24. r = requests.post(f'{base_url}/wiki', json=payload, headers=headers, verify=False)
  25. print(f'Created {slug}: {r.status_code}')
  26. if r.status_code != 201:
  27. print(r.text)
  28. # In Taiga, the home page of the wiki is usually 'home'
  29. push_wiki('home', 'docs/Wiki_Home.md')
  30. push_wiki('26-04-30-plan', 'docs/Scrum_Plan.md')
  31. push_wiki('26-04-30-daily', 'docs/Scrum_Daily.md')
  32. push_wiki('26-04-30-review', 'docs/Scrum_Review.md')
  33. push_wiki('26-04-30-retrospective', 'docs/Scrum_Retro.md')
  34. push_wiki('26-04-30-artifact', 'docs/Scrum_Artifacts.md')