{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import sys, json, datetime\n", "sys.path.insert(0, r'C:\\Users\\tglaubach\\repos\\pydocmaker\\src')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import pydocmaker as pyd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Export reports to Redmine wiki" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Build example document to upload" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/html": [ "

Introduction

\n", "\n", "
dummy text which will be added to the introduction
\n", "\n", "
\n", "\n", "
def hello_world():\n",
       "   print(\"hello world!\")
\n", "\n", "

Second Chapter

\n", "\n", "

This is my fancy markdown text for the Second Chapter

\n", "\n", "
image-name: GitHub-Mark-ea2971cee799.png
\n", "\n", "
\n", "\n", "
caption: GitHub-Mark-ea2971cee799.png
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "doc = pyd.Doc()\n", "doc.add_chapter('Introduction')\n", "doc.add('dummy text which will be added to the introduction')\n", "doc.add_kw('verbatim', 'def hello_world():\\n print(\"hello world!\")')\n", "doc.add_chapter('Second Chapter')\n", "doc.add_kw('markdown', 'This is my fancy `markdown` text for the Second Chapter')\n", "doc.add_image(\"https://github.githubassets.com/assets/GitHub-Mark-ea2971cee799.png\")\n", "doc.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Define the connection to our Redmine server" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "session setting param='headers' with params[param]={'X-Redmine-API-Key': 'your_redmine_token'}\n", "session setting param='params' with params[param]={}\n" ] }, { "data": { "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import redminelib\n", "\n", "# Replace with your Redmine instance URL, and token\n", "my_server = 'https://your-redmine-instance.com'\n", "my_token = 'your_redmine_token'\n", "\n", "redmine = redminelib.Redmine(my_server, key=my_token)\n", "\n", "redmine" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### The easy way: upload via `.upload_report_to_redmine(...)`" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "page = doc.to_redmine_upload(redmine, 'your-test-project')\n", "# page should be the link to your wiki page\n", "page" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### The harder way: export and manual upload" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# here we can not save to a file, but only return the exported values\n", "text_textile, attachments_lst = doc.to_redmine()\n", "\n", "print(text_textile[:100] + '...\\n(rest omitted for brevity)')\n", "\n", "print('-'*100)\n", "print('Attachments')\n", "print('-'*100)\n", "for a in attachments_lst:\n", " print(a.get('filename'), type(a.get('path')), a.get('content_type'))\n", "\n", "# this we can use to upload to redmine, but not save to a file directly\n", "\n", "page_title = 'My Wiki Page'\n", "project_id = 'myproject'\n", "\n", "\n", "page = redmine.wiki_page.new()\n", "page.project_id = project_id\n", "page.title = page_title\n", "\n", "page.text = text_textile\n", "page.uploads = attachments_lst\n", "page.comments = f'updated at {datetime.datetime.now(tz=datetime.timezone.utc).isoformat()}'\n", "page.save()\n", "\n", "\n", "print(\"Wiki page created successfully.\")\n", "\n", "\n" ] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.7" } }, "nbformat": 4, "nbformat_minor": 4 }