Skip to content
Open

Test #23

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
447f9da
jira tickets
larse19 Apr 27, 2022
655fdbf
jira tickets
larse19 Apr 27, 2022
c56857e
jira tickets
larse19 Apr 27, 2022
750a260
jira tickets
larse19 Apr 27, 2022
877918c
jira tickets
larse19 Apr 27, 2022
ee823ec
Merge pull request #16 from TTengs/jira-tickets
larse19 Apr 27, 2022
671f683
attachment links
larse19 Apr 28, 2022
4a1ba97
attachment links
larse19 Apr 28, 2022
6decaa7
attachment links
larse19 Apr 28, 2022
9834740
attachment links
larse19 Apr 28, 2022
d793490
attachment links
larse19 Apr 28, 2022
2b45008
attachment links
larse19 Apr 28, 2022
d73eabd
attachment links
larse19 Apr 28, 2022
c60a62c
attachment links
larse19 May 2, 2022
a06e7fd
attachment links
larse19 May 2, 2022
41077f5
attachment links
larse19 May 2, 2022
12ce516
attachment links
larse19 May 2, 2022
6987046
attachment links
larse19 May 2, 2022
e535b3c
attachment links
larse19 May 2, 2022
0d8acb2
attachment links
larse19 May 2, 2022
8480fe8
attachment links
larse19 May 2, 2022
6c4392c
Merge pull request #17 from TTengs/attachment-link
larse19 May 2, 2022
83af3d9
split auth token into username and api token
larse19 May 2, 2022
436fd97
Update README.md
larse19 May 2, 2022
b143dbb
Update README.md
larse19 May 2, 2022
a8761c3
Update README.md
larse19 May 2, 2022
5ceb379
Update README.md
larse19 May 2, 2022
3ff04b2
Update README.md
larse19 May 2, 2022
44a5ae6
Update README.md
larse19 May 3, 2022
67e2dd7
table of contents
larse19 May 3, 2022
1be7a9b
docs
larse19 May 3, 2022
3a70786
docs
larse19 May 3, 2022
14970b5
cleaning
larse19 May 3, 2022
931ef4d
Merge pull request #18 from TTengs/table-of-contents
larse19 May 3, 2022
ef5ba4c
Update README.md
larse19 May 3, 2022
dae01f5
Merge pull request #19 from TTengs/auth-tokens
larse19 May 3, 2022
d545c10
mmb fix module loader
larse19 May 3, 2022
2befffc
Merge pull request #20 from TTengs/table-of-contents
larse19 May 3, 2022
6875fb5
ting
larse19 May 3, 2022
3450647
ting
larse19 May 3, 2022
5e91bae
ting
larse19 May 3, 2022
2864fb5
Update README.md
larse19 May 3, 2022
78f7fe3
trello boards
larse19 May 3, 2022
6098ed6
Merge pull request #21 from TTengs/trello-boards
larse19 May 3, 2022
59b9691
fixed jira tickets
larse19 May 4, 2022
05c5c5c
abe
TTengs May 4, 2022
8adf68a
fixed jira tickets
larse19 May 4, 2022
5d1393c
fixed jira tickets
larse19 May 4, 2022
12171a5
Merge branch 'main' of https://github.com/TTengs/MarkdownToConfluence…
larse19 May 4, 2022
59a56a4
fdf
larse19 May 4, 2022
f604b71
ref test
larse19 May 4, 2022
5be13b7
ref test
larse19 May 4, 2022
1c13be0
ref test
larse19 May 4, 2022
e6fd4e0
ref test
larse19 May 4, 2022
b75ef28
ref test
larse19 May 4, 2022
9d36637
ref test
larse19 May 4, 2022
ae7f5cd
ref test
larse19 May 4, 2022
deff0c6
ref test
larse19 May 4, 2022
8c09f6f
ref test
larse19 May 4, 2022
33ab642
ref test
larse19 May 4, 2022
de3d121
ref test
larse19 May 4, 2022
f6975bd
ref test
larse19 May 4, 2022
e9ecbae
ref test
larse19 May 4, 2022
e651e6d
push test
larse19 May 4, 2022
f68b064
event test
larse19 May 4, 2022
b3b4a7f
event test
larse19 May 4, 2022
2e70799
event test
larse19 May 4, 2022
3e600bd
event test
larse19 May 4, 2022
6530b50
event test
larse19 May 4, 2022
8a1fdb6
event test
larse19 May 4, 2022
f035c3a
event test
larse19 May 4, 2022
dbe805a
event test
larse19 May 4, 2022
901d8e6
event test
larse19 May 4, 2022
2e527fe
event test
larse19 May 4, 2022
7a69036
event test
larse19 May 4, 2022
4ddd71f
event test
larse19 May 4, 2022
ffb77c3
event test
larse19 May 4, 2022
b222a5b
event test
larse19 May 4, 2022
3dce8dd
event test
larse19 May 4, 2022
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
17 changes: 11 additions & 6 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: Upload Documentation

on:
pull_request:
branches:
- main
# on:
# pull_request:
# branches:
# - main

on: [push]

jobs:
hello_world_job:
Expand All @@ -14,10 +16,13 @@ jobs:
uses: actions/checkout@v3
- name: Conversion step
env:
CONFLUENCE_URL: 'https://at-bachelor.atlassian.net/wiki'
CONFLUENCE_URL: 'https://at-bachelor.atlassian.net'
CONFLUENCE_SPACE_KEY: '~955037829'
AUTH_TOKEN: ${{ secrets.AUTH_TOKEN }}
AUTH_USERNAME: ${{ secrets.AUTH_USERNAME }}
AUTH_API_TOKEN: ${{ secrets.AUTH_API_TOKEN }}
uses: ./ # Uses an action in the root directory
id: Convert
with:
fileslocation: './documentation'


9 changes: 3 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: Run PyTest

on: [push]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -19,16 +16,16 @@ jobs:
apt-get update && apt-get install -y python3-venv
python3 -m venv venv
. venv/bin/activate
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install -e .
- name: Test with pytest
env:
CONFLUENCE_URL: 'https://at-bachelor.atlassian.net/wiki'
CONFLUENCE_SPACE_KEY: '~955037829'
AUTH_TOKEN: ${{ secrets.AUTH_TOKEN }}
AUTH_USERNAME: ${{ secrets.AUTH_USERNAME }}
AUTH_API_TOKEN: ${{ secrets.AUTH_API_TOKEN }}
INPUT_FILESLOCATION: './documentation'
run: |
. venv/bin/activate
pip install -e .
pytest -v
python3 -m pytest -v
33 changes: 18 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
FROM ubuntu:latest

RUN apt-get update && apt-get install -y software-properties-common gcc && \
add-apt-repository -y ppa:deadsnakes/ppa
RUN apt-get update
#&& apt-get install -y software-properties-common gcc && \
# add-apt-repository -y ppa:deadsnakes/ppa

RUN apt-get install -y python3.6 python3-distutils python3-pip python3-apt python3-venv
#RUN apt-get install -y python3.6 python3-distutils python3-pip python3-apt python3-venv

RUN apt-get install -y pandoc
RUN apt-get install -y git jq

# RUN apt-get install -y pandoc
#ffmpeg libsm6 libxext6

RUN python3 -m venv venv
RUN chmod +x /venv/*
RUN . /venv/bin/activate
# RUN python3 -m venv venv
# RUN chmod +x /venv/*
# RUN . /venv/bin/activate

COPY setup.py /setup.py
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
# COPY setup.py /setup.py
# COPY requirements.txt requirements.txt
# RUN pip install -r requirements.txt
COPY ./MarkdownToConfluence /MarkdownToConfluence
RUN pip install -e .
# RUN pip install -e .


RUN chmod +x /MarkdownToConfluence/convert_all.sh
RUN chmod +x /MarkdownToConfluence/convert.sh
#RUN chmod +x /MarkdownToConfluence/entrypoint.sh
# RUN chmod +x /MarkdownToConfluence/convert_all.sh
# RUN chmod +x /MarkdownToConfluence/convert.sh
RUN chmod +x /MarkdownToConfluence/entrypoint.sh

ENTRYPOINT [ "sh", "/MarkdownToConfluence/convert_all.sh" ]
ENTRYPOINT [ "bash", "/MarkdownToConfluence/entrypoint.sh" ]
1 change: 1 addition & 0 deletions MarkdownToConfluence/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__all__ = ['utils', 'modules', 'confluence', 'globals']
24 changes: 14 additions & 10 deletions MarkdownToConfluence/confluence/check_if_page_exists.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
from urllib.parse import quote
import requests, json
import os
from requests.auth import HTTPBasicAuth

from MarkdownToConfluence.confluence.PageNotFoundError import PageNotFoundError

AUTH_TOKEN = os.environ.get("AUTH_TOKEN")
BASE_URL = os.environ.get("CONFLUENCE_URL")
AUTH_USERNAME = os.environ.get("AUTH_USERNAME")
AUTH_API_TOKEN = os.environ.get("AUTH_API_TOKEN")

authorization_string = f"Basic {AUTH_TOKEN}"
auth = HTTPBasicAuth(AUTH_USERNAME, AUTH_API_TOKEN)

def page_exists_in_space(title: str, spaceKey: str) -> bool:
url = f"{BASE_URL}/rest/api/content?spaceKey={spaceKey}&title={quote(title)}"
url = f"{BASE_URL}/wiki/rest/api/content?spaceKey={spaceKey}&title={quote(title)}"
headers = {
'Authorization': authorization_string,
'User-Agent': 'python'
}
response = requests.request('GET', url, headers=headers)
response = requests.request('GET', url, headers=headers, auth=auth)
if(response.status_code == 200):
results = json.loads(response.text)['results']
if(len(results) > 0):
Expand All @@ -22,19 +25,20 @@ def page_exists_in_space(title: str, spaceKey: str) -> bool:
return False
else:
print(response.text)
return False

def get_page_id(title: str, spaceKey: str) -> str:
url = f"{BASE_URL}/rest/api/content?spaceKey={spaceKey}&title={quote(title)}"
url = f"{BASE_URL}/wiki/rest/api/content?spaceKey={spaceKey}&title={quote(title)}"
headers = {
'Authorization': authorization_string,
'User-Agent': 'python'
}
response = requests.request('GET', url, headers=headers)
response = requests.request('GET', url, headers=headers, auth=auth)
if(response.status_code == 200):
results = json.loads(response.text)['results']
if(len(results) > 0):
return results[0]['id']
else:
return 'Page does not exist'
raise PageNotFoundError(title, spaceKey)
else:
print(response.text)
print(response.text)
raise PageNotFoundError(title, spaceKey)
13 changes: 7 additions & 6 deletions MarkdownToConfluence/confluence/create_content.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import json
import codecs
import requests
import sys, os
import sys, os, base64
from requests.auth import HTTPBasicAuth

AUTH_TOKEN = os.environ.get("AUTH_TOKEN")
BASE_URL = os.environ.get("CONFLUENCE_URL")
AUTH_USERNAME = os.environ.get("AUTH_USERNAME")
AUTH_API_TOKEN = os.environ.get("AUTH_API_TOKEN")

authorization_string = f"Basic {AUTH_TOKEN}"
auth = HTTPBasicAuth(AUTH_USERNAME, AUTH_API_TOKEN)

def create_page(filename: str, title: str, space_obj, parent_id="none"):
filename = filename.replace(".md", ".html")
Expand Down Expand Up @@ -45,16 +47,15 @@ def create_page(filename: str, title: str, space_obj, parent_id="none"):
f = codecs.open(f"{filename}", 'r', encoding='utf-8')
template['body']['storage']['value'] = f.read()

url = f'{BASE_URL}/rest/api/content'
url = f'{BASE_URL}/wiki/rest/api/content'

headers = {
'Authorization': authorization_string,
'Content-Type': 'application/json; charset=utf-8',
'User-Agent': 'python'
}

# Upload html to confluence
response = requests.request("POST", url, headers=headers, data=json.dumps(template))
response = requests.request("POST", url, headers=headers, data=json.dumps(template), auth=auth)

return response

Expand Down
26 changes: 12 additions & 14 deletions MarkdownToConfluence/confluence/delete_content.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import requests, json
from MarkdownToConfluence.filetools import get_all_page_names_in_filesystem
import sys, os
from MarkdownToConfluence.utils import get_all_page_names_in_filesystem
import sys, os, base64
from requests.auth import HTTPBasicAuth

#BASE_URL = os.environ.get("CONFLUENCE_URL")
BASE_URL = 'https://at-bachelor.atlassian.net/wiki'
BASE_URL = os.environ.get("CONFLUENCE_URL")
FILES_PATH = os.environ.get("INPUT_FILESLOCATION")
#AUTH_TOKEN = os.environ.get("AUTH_TOKEN")
AUTH_TOKEN = "bGFyc2UxOUBzdHVkZW50LnNkdS5kazp6RzFrQk1ick9PUEtZblNSSFA0bTQxNUI="
SPACE_KEY = os.environ.get("CONFLUENCE_SPACE_KEY")
AUTH_USERNAME = os.environ.get("AUTH_USERNAME")
AUTH_API_TOKEN = os.environ.get("AUTH_API_TOKEN")

authorization_string = f"Basic {AUTH_TOKEN}"
auth = HTTPBasicAuth(AUTH_USERNAME, AUTH_API_TOKEN)

def delete_page(page_id: str, page_name=""):

url = f"{BASE_URL}/rest/api/content/{page_id}"
url = f"{BASE_URL}/wiki/rest/api/content/{page_id}"

headers = {
'Authorization': authorization_string,
'User-Agent': 'python'
}

response = requests.request('DELETE', url, headers=headers)
response = requests.request('DELETE', url, headers=headers, auth=auth)

if(response.status_code == 204):
print(f"Deleted {page_id} {page_name}")
Expand All @@ -33,21 +32,20 @@ def delete_page(page_id: str, page_name=""):
the exclude arg takes a list of page names, that are not to be deleted, even if they dont exist in the filesystem
"""
def delete_non_existing_pages(space_key: str, root: str, exclude=['Overview']):
url = f"{BASE_URL}/rest/api/content?spaceKey={space_key}"
url = f"{BASE_URL}/wiki/rest/api/content?spaceKey={space_key}"

headers = {
'Authorization': authorization_string,
'User-Agent': 'python'
}

results = []
response = requests.request("GET", url, headers=headers)
response = requests.request("GET", url, headers=headers, auth=auth)
response_json = json.loads(response.text)
if(response.status_code == 200):
results.extend(response_json['results'])
while("next" in response_json['_links']):
url = BASE_URL + response_json["_links"]["next"]
response = requests.request("GET", url, headers=headers)
response = requests.request("GET", url, headers=headers, auth=auth)
response_json = json.loads(response.text)
results.extend(response_json['results'])

Expand Down
15 changes: 8 additions & 7 deletions MarkdownToConfluence/confluence/update_content.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import json
import codecs
import requests
import os
import os, base64
from requests.auth import HTTPBasicAuth

AUTH_TOKEN = os.environ.get("AUTH_TOKEN")
BASE_URL = os.environ.get("CONFLUENCE_URL")
AUTH_USERNAME = os.environ.get("AUTH_USERNAME")
AUTH_API_TOKEN = os.environ.get("AUTH_API_TOKEN")

authorization_string = f"Basic {AUTH_TOKEN}"
auth = HTTPBasicAuth(AUTH_USERNAME, AUTH_API_TOKEN)

def update_page_content(filename: str, title: str, page_id: str, space_obj,):
filename = filename.replace(".md", ".html")
Expand Down Expand Up @@ -37,21 +39,20 @@ def update_page_content(filename: str, title: str, page_id: str, space_obj,):
f = codecs.open(f"{filename}", 'r', encoding='utf-8')
template['body']['storage']['value'] = f.read()

url = f"{BASE_URL}/rest/api/content/{page_id}"
url = f"{BASE_URL}/wiki/rest/api/content/{page_id}"

headers = {
'Authorization': authorization_string,
'Content-Type': 'application/json; charset=utf-8',
'User-Agent': 'python'
}

# Get current version
get_response = requests.request("GET", f"{url}?expand=version", headers=headers)
get_response = requests.request("GET", f"{url}?expand=version", headers=headers, auth=auth)
version_number = int(json.loads(get_response.text)['version']['number'])
template['version']['number'] = version_number + 1

# Upload html to confluence
put_response = requests.request("PUT", url, headers=headers, data=json.dumps(template))
put_response = requests.request("PUT", url, headers=headers, data=json.dumps(template), auth=auth)

if(put_response.status_code != 200):
print(template['body'])
Expand Down
38 changes: 9 additions & 29 deletions MarkdownToConfluence/confluence/upload_attachments.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
import requests, json, os
import requests, json, os, base64
from .check_if_page_exists import page_exists_in_space, get_page_id
from .PageNotFoundError import PageNotFoundError
from requests.auth import HTTPBasicAuth

BASE_URL = os.environ.get("CONFLUENCE_URL")
AUTH_TOKEN = os.environ.get("AUTH_TOKEN")
SPACEKEY = os.environ.get("CONFLUENCE_SPACE_KEY")
AUTH_USERNAME = os.environ.get("AUTH_USERNAME")
AUTH_API_TOKEN = os.environ.get("AUTH_API_TOKEN")

authorization_string = f"Basic {AUTH_TOKEN}"
auth = HTTPBasicAuth(AUTH_USERNAME, AUTH_API_TOKEN)

headers = {
'Authorization': authorization_string,
'User-Agent': 'python',
'X-Atlassian-Token': 'no-check'
}

def upload_attachment(page_title, attactchment_name, filepath):
if(page_exists_in_space(page_title, SPACEKEY)):
url = f"{BASE_URL}/rest/api/content/{get_page_id(page_title, SPACEKEY)}/child/attachment"
url = f"{BASE_URL}/wiki/rest/api/content/{get_page_id(page_title, SPACEKEY)}/child/attachment"

# Get attachment id
id = ""
attachments = requests.get(url, headers=headers)
attachments = requests.get(url, headers=headers, auth=auth)
for result in json.loads(attachments.text)['results']:
if(result['title'] == attactchment_name):
id = result['id']
if(id == ""): # Attachment doesnt exist, create it
# Create attachment
file = {'file': (attactchment_name, open(filepath, 'rb'))}
response = requests.post(url, headers=headers, files=file)
response = requests.post(url, headers=headers, files=file, auth=auth)
else: # Attachment exists, update it
# Update attachment
files = {'file': (attactchment_name, open(os.path.abspath(filepath), 'rb'))}
response = requests.post(f'{url}/{id}/data', headers=headers, files=files)
response = requests.post(f'{url}/{id}/data', headers=headers, files=files, auth=auth)

if(response.status_code == 200):
print(f"Uploaded {attactchment_name} as attachment on page {page_title}")
Expand All @@ -40,24 +41,3 @@ def upload_attachment(page_title, attactchment_name, filepath):
return response
else:
raise PageNotFoundError(page_title, SPACEKEY)

"""
def update_attachment_data(page_title, attactchment_name, filepath):
if(page_exists_in_space(page_title, SPACEKEY)):
url = f"{BASE_URL}/rest/api/content/{get_page_id(page_title, SPACEKEY)}/child/attachment"

# Get attachment id
id = ""
attachments = requests.get(url, headers=headers)
for result in json.loads(attachments.text)['results']:
if(result['title'] == attactchment_name):
id = result['id']

# Update attachment
files = {'file': (f'{attactchment_name}', open(f'./{filepath}', 'rb'))}
response = requests.post(url + f'/{id}/data', headers=headers, files=files)

return response
else:
raise PageNotFoundError(page_title, SPACEKEY)
"""
Loading