Commit 22fc2b06 authored by aparcar's avatar aparcar

add fs2gitlab.py script

Signed-off-by: aparcar's avatarPaul Spooren <mail@aparcar.org>
parent 45f74cc5
Pipeline #436 passed with stage
in 28 seconds
# FlySpray to GitLab migrator
1. Retreive a database dump.
2. Run a local database containing the issues via the following command.
```
sudo docker run -v "$(pwd)/flyspray.sql:/docker-entrypoint-initdb.d/fs.sql" -e
MYSQL_ROOT_PASSWORD=bugs -e MYSQL_DATABASE=bugs --rm mariadb:latest
```
3. Run `python3 fs2gitlab.py`
4. Wait a very long time
import gitlab
from multiprocessing import Pool
import peewee as pw
import time
import random
with open("token_com", "r") as token_file:
token = token_file.readline()[:-1]
gl = gitlab.Gitlab("https://gitlab.com", private_token=token)
gl.auth()
project = gl.projects.get(14341737)
db = pw.MySQLDatabase("bugs", host="172.17.0.2", port=3306, user="root", passwd="bugs")
db.connect()
def add_task(task):
try:
issue = project.issues.get(task[0])
print("-", end="", flush=True)
except:
labels = []
if task[3] != "Feature Request":
labels.append("type:" + task[3])
issue_gl = {
"id": "openwrt/openwrt",
"iid": task[0],
"created_at": task[1],
"title": task[7],
"labels": labels,
"description": task[8].replace("@", "@ "),
}
for x in range(100):
time.sleep(10)
try:
issue = project.issues.create(issue_gl)
break
except:
print("#", end="", flush=True)
print("+", end="", flush=True)
# is closed
if task[4]:
issue.state_event = "close"
print("x", end="", flush=True)
with open("select_comments.sql", "r") as comments_file:
cursor = db.execute_sql(comments_file.read(), params=(str(task[0])))
comments = cursor.fetchall()
for comment in comments[len(issue.notes.list()) :]:
try:
issue.notes.create(
{"created_at": comment[0], "body": comment[1].replace("@", "@ ")}
)
except:
print(comment)
print("o", end="", flush=True)
time.sleep(1)
issue.save()
time.sleep(1)
with open("select_tasks.sql", "r") as tasks_file:
cursor = db.execute_sql(tasks_file.read())
tasks = list(cursor.fetchall())
random.shuffle(tasks)
pool = Pool(10)
pool.map(add_task, tasks)
SELECT
comments.date_added,
comments.comment_text
FROM
flyspray_comments AS comments
WHERE
comments.task_id = %s
ORDER BY
comments.date_added
SELECT
tasks.task_id,
tasks.date_opened,
tasks.task_type AS tasktype_id,
tasktypes.tasktype_name AS tasktype,
tasks.is_closed,
tasks.date_closed,
tasks.closure_comment,
tasks.item_summary,
tasks.detailed_desc,
tasks.resolution_reason AS resolution_id,
resolutions.resolution_name,
tasks.operating_system AS os_id,
os.os_name AS os_name,
tasks.last_edited_time,
(tasks.last_edited_by > 0) AS was_edited
FROM
flyspray_tasks AS tasks,
flyspray_list_resolution AS resolutions,
flyspray_list_os AS os,
flyspray_list_tasktype AS tasktypes
WHERE
tasks.resolution_reason = resolutions.resolution_id AND
tasks.operating_system = os.os_id AND
tasks.task_type = tasktypes.tasktype_id
order by
tasks.last_edited_time desc
......@@ -3,12 +3,14 @@
set -euo pipefail
MIRROR_REPOS=" \
openwrt/openwrt \
project/procd \
openwrt/openwrt \
project/firewall3 \
project/uci \
project/ubus \
project/rpcd \
project/netifd \
buildbot \
"
log() {
......@@ -40,7 +42,8 @@ init_repo() {
git clone --mirror "${src}/${repo_path}.git" "$repo"
pushd "$repo" > /dev/null
git remote add --mirror=fetch target "git@code.fe80.eu:openwrt/$repo.git"
#git remote add --mirror=fetch target "git@code.fe80.eu:openwrt/$repo.git"
git remote add --mirror=fetch target "git@gitlab.com:openwrtorg/$repo.git"
git push target --all
popd > /dev/null
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment