├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── bashrc ├── update-confluence └── vimrc /Dockerfile: -------------------------------------------------------------------------------- 1 | # Dockerfile 2 | 3 | FROM python:2-slim 4 | 5 | WORKDIR /srv 6 | 7 | RUN apt-get update ;\ 8 | apt-get -y install curl git vim-tiny;\ 9 | pip install mdtohtml 10 | 11 | COPY update-confluence /usr/bin/update-confluence 12 | COPY bashrc /etc/bash.bashrc 13 | COPY vimrc /etc/vim/vimrc.tiny 14 | COPY vimrc /etc/vim/vimrc -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2018, Zonky 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | help: 5 | @cat README.md 6 | @echo "\n\n" 7 | @echo "Usage:" 8 | @echo " make build - build image" 9 | @echo " make publish - build image" 10 | @echo " make test - build image" 11 | 12 | build: 13 | docker build -t zonkyio/confluence-sync . --no-cache 14 | 15 | publish: 16 | docker push zonkyio/confluence-sync 17 | 18 | test: 19 | docker run --rm -it -e JIRA_USER=myemail@gmail.com -e JIRA_PASSWORD=SuperCOOLpassWord iapp/confluence-sync confluence-update FILE_PATH.md PAGE_ID "Page name in confluence" 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Autoupdate confluence from git README 2 | ===================================== 3 | 4 | You can use it to sync your git documentation to confluence PRECREATED page 5 | 6 | 7 | How does it work 8 | ---------------- 9 | - start docker container with all tools 10 | - by command **update-confluence** convert and upload file to confluence 11 | 12 | 13 | How to use it in pipeline 14 | ------------------------- 15 | 16 | When you would like to sync documentation just on merge/push to master, put to bitbucket-pipeline.yml code like this: 17 | 18 | set env variable JIRA_USER and JIRA_PASSWORD to allow updater write access to page 19 | 20 | 21 | image: zonkyio/confluence-sync 22 | 23 | pipelines: 24 | branches: 25 | master: 26 | - step: 27 | script: 28 | - update-confluence README.md TICKET_ID "Autoupdate documentation from git repo" 29 | - update-confluence README2.md TICKET_ID2 "Autoupdate documentation from git repo" 30 | 31 | 32 | 33 | -- version 0.10 34 | -------------------------------------------------------------------------------- /bashrc: -------------------------------------------------------------------------------- 1 | export PS1="\e[0;34m\h@\W: \e[0;32m><> \e[0m" 2 | 3 | alias ll="ls -al --color" 4 | alias jq="python -mjson.tool" 5 | alias vi="vim.tiny" 6 | alias vim="vim.tiny" 7 | -------------------------------------------------------------------------------- /update-confluence: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | # set in env 5 | # JIRA_USER 6 | # JIRA_PASSWORD 7 | 8 | 9 | # arguments 10 | SOURCE_FILE=${1} 11 | ID=${2} 12 | TITLE=${3} 13 | 14 | 15 | 16 | FNAME="$(basename ${SOURCE_FILE} | cut -d. -f1)" 17 | 18 | next_version=$(curl -u ${JIRA_USER}:${JIRA_PASSWORD} -X GET -H 'Content-Type: application/json' \ 19 | https://hcpeer2peer.atlassian.net/wiki/rest/api/content/${ID} | python -c 'import json, sys; print(json.load(sys.stdin)["version"]["number"] + 1)') 20 | 21 | mdtohtml ${SOURCE_FILE} /tmp/__${FNAME} 22 | 23 | curl -u ${JIRA_USER}:${JIRA_PASSWORD} -X PUT -H 'Content-Type: application/json' https://hcpeer2peer.atlassian.net/wiki/rest/api/content/${ID} \ 24 | -d @- << EOF 25 | { 26 | "id": "${ID}", 27 | "type": "page", 28 | "title": "${TITLE}", 29 | "body": { 30 | "storage": { 31 | "value": "$(cat /tmp/__${FNAME} | sed 's/\"/\\\\"/g' | while read l; do echo "$l"; done)", 32 | "representation":"storage" 33 | } 34 | }, 35 | "version":{ 36 | "number": ${next_version} 37 | } 38 | } 39 | EOF 40 | -------------------------------------------------------------------------------- /vimrc: -------------------------------------------------------------------------------- 1 | set nocompatible 2 | set showcmd 3 | set showmatch --------------------------------------------------------------------------------