Reorganize docs.

This commit is contained in:
Lauri Ojansivu 2024-06-27 14:01:26 +03:00
parent ea5d0999c4
commit 057ac4031e
22 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,8 @@
# v1.0 2022-03-22 Perl Asana export to WeKan ® release
This release adds the following new features:
- [Added Perl scripts for Asana export to WeKan ®](https://github.com/wekan/wekan/commit/376bcbb373d16317060adc2b1154cc20496775cc).
Thanks to GeekRuthie.
Thanks to above GitHub users for their contributions and translators for their translations.

View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2022 WeKan ® Team and GeekRuthie
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,178 @@
#!/usr/local/perl-cbt/bin/perl
use Modern::Perl;
use Carp;
use Data::Dumper;
use HTTP::Request;
use JSON;
use LWP::UserAgent;
use MIME::Base64 qw/encode_base64/;
my $BASE_URL = 'https://app.asana.com/api/1.0';
my $ASANA_API_KEY = 'ASANA_PERSONAL_TOKEN';
my $ua = LWP::UserAgent->new();
open my $input_wekan, '<', 'template.json';
my $wekan_json = readline($input_wekan);
close $input_wekan;
my $wekan_board = decode_json($wekan_json);
my %users;
my %users_by_gid;
# get user IDs from template board
foreach my $user ( @{ $wekan_board->{users} } ) {
$users{ $user->{profile}->{fullname} } = $user->{_id};
}
# get list IDs from template (we ended up not using these)
my %lists;
foreach my $list ( @{ $wekan_board->{lists} } ) {
$lists{ $list->{title} } = $list->{_id};
}
my @headers;
push @headers, ( 'Accept', 'application/json' );
push @headers, ( 'Authorization', "Bearer $ASANA_API_KEY" );
my $projects_req = HTTP::Request->new( "GET", "$BASE_URL/projects", \@headers, );
my $projects_res = $ua->request($projects_req);
my $projects = decode_json( $projects_res->content )->{data};
foreach my $project (@$projects) {
say "Project: ".$project->{name};
my $tasks_url =
'/tasks?project='
. $project->{gid}
. '&opt_fields=completed,name,notes,assignee,created_by,memberships.project.name, memberships.section.name,due_on,created_at,custom_fields';
my $tasks_req = HTTP::Request->new( 'GET', "$BASE_URL$tasks_url", \@headers );
my $tasks_res = $ua->request($tasks_req);
my @output_tasks;
my $tasks = decode_json( $tasks_res->content )->{data};
foreach my $task (@$tasks) {
next if $task->{completed};
say ' - '.$task->{name};
my $git_branch;
my $prio;
foreach my $custom ( @{ $task->{custom_fields} } ) {
if ( $custom->{name} eq 'git branch' ) {
$git_branch = $custom->{text_value};
next;
}
# We ended up not importing these.
if ( $custom->{name} eq 'Priority' && defined $custom->{display_value} ) {
$prio =
$custom->{display_value} eq 'High' ? 'fwccC9'
: $custom->{display_value} eq 'Med' ? 'yPnaFa'
: $custom->{display_value} eq 'Low' ? 'W4vMvm'
: 'ML5drH';
next;
}
}
if ( !defined $users_by_gid{ $task->{created_by}->{gid} } ) {
my $user_req =
HTTP::Request->new( 'GET', "$BASE_URL/users/" . $task->{created_by}->{gid},
\@headers );
my $user_res = $ua->request($user_req);
my $user = decode_json( $user_res->content )->{data};
if ( defined $users{ $user->{name} } ) {
$users_by_gid{ $task->{created_by}->{gid} } = $users{ $user->{name} };
}
}
my $creator = $users_by_gid{ $task->{created_by}->{gid} } // undef;
if ( defined $task->{assignee} && !defined $users_by_gid{ $task->{assignee}->{gid} } ) {
my $user_req =
HTTP::Request->new( 'GET', "$BASE_URL/users/" . $task->{assignee}->{gid},
\@headers );
my $user_res = $ua->request($user_req);
my $user = decode_json( $user_res->content )->{data};
if ( defined $users{ $user->{name} } ) {
$users_by_gid{ $task->{assignee}->{gid} } = $users{ $user->{name} };
}
}
my $assignee = defined $task->{assignee} ? $users_by_gid{ $task->{assignee}->{gid} } : undef;
my $list;
foreach my $membership ( @{ $task->{memberships} } ) {
next if $membership->{project}->{name} ne $project->{name};
$list = $membership->{section}->{name};
}
# I was trying to create JSON that I could use on the import screen in Wekan,
# but for bigger boards, it was just *too* hefty, so I took that JSON and used
# APIs to import.
my %output_task = (
swimlaneId => 'As4SNerx4Y4mMnJ8n', # 'Bugs'
sort => 0,
type => 'cardType-card',
archived => JSON::false,
title => $task->{name},
description => $task->{notes},
createdAt => $task->{created_at},
dueAt => defined $task->{due_on} ? $task->{due_on} . 'T22:00:00.000Z' : undef,
customFields => [
{
_id => 'rL8BpFHp5xxSFbDdr',
value => $git_branch,
},
],
labelIds => [$prio],
listId => $list,
userId => $creator,
assignees => [$assignee],
);
my @final_comments;
my $comments_req =
HTTP::Request->new( 'GET', "$BASE_URL/tasks/" . $task->{gid} . '/stories',
\@headers );
my $comments_res = $ua->request($comments_req);
my $comments = decode_json( $comments_res->content )->{data};
foreach my $comment (@$comments) {
next if $comment->{type} ne 'comment';
if ( !defined $users_by_gid{ $comment->{created_by}->{gid} } ) {
my $user_req =
HTTP::Request->new( 'GET', "$BASE_URL/users/" . $comment->{created_by}->{gid},
\@headers );
my $user_res = $ua->request($user_req);
my $user = decode_json( $user_res->content )->{data};
if ( defined $users{ $user->{name} } ) {
$users_by_gid{ $comment->{created_bye}->{gid} } = $users{ $user->{name} };
}
}
my $commentor = $users_by_gid{ $comment->{created_by}->{gid} };
my %this_comment = (
text => $comment->{text},
createdAt => $comment->{created_at},
userId => $commentor,
);
push @final_comments, \%this_comment;
}
$output_task{comments} = \@final_comments;
my @final_attachments;
my $attachments_req =
HTTP::Request->new( 'GET', "$BASE_URL/tasks/" . $task->{gid} . '/attachments',
\@headers );
my $attachments_res = $ua->request($attachments_req);
my $attachments = decode_json( $attachments_res->content )->{data};
foreach my $attachment (@$attachments) {
my $att_req =
HTTP::Request->new( 'GET', "$BASE_URL/attachments/" . $attachment->{gid},
\@headers );
my $att_res = $ua->request($att_req);
my $att = decode_json( $att_res->content )->{data};
my $file_req=HTTP::Request->new('GET',$att->{download_url});
my $file_res=$ua->request($file_req);
my $file=encode_base64($file_res->content);
my %this_attachment = (
file => $file,
name => $att->{name},
createdAt => $att->{created_at},
);
push @final_attachments, \%this_attachment;
}
$output_task{attachments} = \@final_attachments;
push @output_tasks, \%output_task;
}
my $file_name = $project->{name};
$file_name =~ s/\//_/g;
open my $output_file, '>',$file_name.'_exported.json';
print $output_file encode_json(\@output_tasks);
close $output_file;
}

View file

@ -0,0 +1,122 @@
#!/usr/local/perl-cbt/bin/perl
use Modern::Perl;
use Carp;
use Data::Dumper;
use HTTP::Request;
use JSON;
use LWP::UserAgent;
use MIME::Base64 qw/decode_base64/;
use Try::Tiny;
my $BASE_URL = 'https://taskboard.example.com/api';
my $TOKEN = 'MY_TOKEN';
my $me = 'MY_USER_ID';
my $ua = LWP::UserAgent->new();
my @headers;
push @headers, ( 'Accept', 'application/json' );
push @headers, ( 'Authorization', "Bearer $TOKEN" );
my @form_headers;
push @form_headers, ( 'Content-Type', 'application/json' );
push @form_headers, ( 'Accept', 'application/json' );
push @form_headers, ( 'Authorization', "Bearer $TOKEN" );
# Prior to running this, I built all the boards, with labels and lists and swimlanes.
# Grabbed the IDs for the boards for each project, and put them here to match up with
# filenames from the Asana export script.
my %board_to_use = (
Project_1 => 'F5ZiCXnf4d7qNBRjp',
Project_2 => 'Shw3tyfC2JWCutBLj',
);
opendir my $files_dir, '.'
or croak "Cannot open input directory: $!";
my @files = readdir $files_dir;
closedir $files_dir;
foreach my $tasks_file (@files) {
next if $tasks_file !~ /_exported.json/;
my $project = $tasks_file;
$project =~ s/_exported.json//;
say "Project - $project";
my $board;
if ( $board_to_use{$project} ) {
$board = $board_to_use{$project};
}
say ' No board!' if !$board;
next if !$board;
my $labels_req = HTTP::Request->new( 'GET', "$BASE_URL/boards/$board", \@headers );
my $labels_res = $ua->request($labels_req);
my $board_data = decode_json( $labels_res->content);
my $labels = $board_data->{labels};
my $label_to_use;
# We're merging several Asana boards onto one Wekan board, with labels per project.
foreach my $label (@$labels) {
$label_to_use = $label->{_id} if $label->{name} eq $project;
}
my $lanes_req = HTTP::Request->new( 'GET', "$BASE_URL/boards/$board/swimlanes", \@headers );
my $lanes_res = $ua->request($lanes_req);
my $lanes = decode_json( $lanes_res->content );
my $lane_to_use;
foreach my $lane (@$lanes) {
# Our Asana didn't use swimlanes; all of our Wekan boards have a "Bugs" lane, so use that.
$lane_to_use = $lane->{_id} if $lane->{title} eq 'Bugs';
}
my $lists_req = HTTP::Request->new( 'GET', "$BASE_URL/boards/$board/lists", \@headers );
my $lists_res = $ua->request($lists_req);
my $lists = decode_json( $lists_res->content );
my %list_to_use;
foreach my $list (@$lists) {
$list_to_use{ $list->{title} } = $list->{_id};
}
open my $task_export_file, '<', $tasks_file;
my $tasks_json = readline($task_export_file);
close $task_export_file;
my $tasks = decode_json($tasks_json);
foreach my $task (@$tasks) {
say ' - ' . $task->{title};
my %body_info = (
swimlaneId => $lane_to_use,
authorId => $task->{userId},
assignees => $task->{assignees},
title => $task->{title},
description => $task->{description},
);
my $body = encode_json( \%body_info );
my $list = $list_to_use{ $task->{listId} } // $list_to_use{'Backlog'};
my $task_req = HTTP::Request->new( 'POST', "$BASE_URL/boards/$board/lists/$list/cards",
\@form_headers, $body );
my $task_res = $ua->request($task_req);
my $res;
try {
$res = decode_json( $task_res->content );
} catch {
# Did these manually afterward.
say "--->UNABLE TO LOAD TASK";
next;
};
my $card = $res->{_id};
if ($label_to_use) {
my $card_edit_body = encode_json( { labelIds => [ $label_to_use ]});
my $card_edit_req = HTTP::Request->new( 'PUT', "$BASE_URL/boards/$board/lists/$list/cards/$card",
\@form_headers, $card_edit_body );
my $card_edit_res = $ua->request($card_edit_req);
}
foreach my $comment ( @{ $task->{comments} } ) {
my $comment_body =
encode_json( { authorId => $comment->{userId}, comment => $comment->{text} } );
my $comment_req =
HTTP::Request->new( 'POST', "$BASE_URL/boards/$board/cards/$card/comments",
\@form_headers, $comment_body );
my $comment_res = $ua->request($comment_req);
}
}
}

View file

@ -0,0 +1,9 @@
# v1.0 2021-12-26 WeKan ® Python Trello API CLI release
This release adds the following new features:
- [Added api.py for using newest Trello API, to show Trello boards/cards/actions/reactions JSON and download Trello attachments
as binary files from S3](https://github.com/wekan/wekan/commit/aff6e361f03f1a7e269edc184884313557c94362).
Thanks to xet7.
Thanks to above GitHub users for their contributions and translators for their translations.

View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2021-2022 The Wekan Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

180
docs/ImportExport/trello/api.py Executable file
View file

@ -0,0 +1,180 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# vi:ts=4:et
# Trello API Python CLI
# License: MIT / WeKan Team
try:
# python 3
from urllib.parse import urlencode
from urllib.request import urlretrieve
except ImportError:
# python 2
from urllib import urlencode
import json
import requests
import sys
# ------- TODO START -------------
#
# - Check nested resources about how to recursively get all reactins etc:
# https://developer.atlassian.com/cloud/trello/guides/rest-api/nested-resources/
# - Add checking status codes and stop/delay if errors in API.
# If board is big, instead get small amount of board with paging of Trello REST API,
# then have small delay, and then get more of that big amount of data, so that
# there would not be timeouts with too much data
# https://developer.atlassian.com/cloud/trello/guides/rest-api/status-codes/
# - Add batch requests, to get enough data at once:
# https://developer.atlassian.com/cloud/trello/rest/api-group-batch/#api-batch-get
# - Add rate limits with delays:
# https://developer.atlassian.com/cloud/trello/guides/rest-api/rate-limits/
# - Use webhooks to receive data from Trello to WeKan, so that there would not be
# need to repeatedly get same data again (no polling data), but instead get
# changes pushed to WeKan with webhooks when they happen
# https://developer.atlassian.com/cloud/trello/guides/rest-api/webhooks/
# https://developer.atlassian.com/cloud/trello/rest/api-group-webhooks/#api-webhooks-post
#
# ------- TODO END -------------
# ------- TRELLO SETTINGS START -------------
#
# READ ABOVE TODO FIRST, BE CAREFUL WITH RATE LIMITS ETC.
#
# Keys and tokens:
# - See API introduction:
# https://developer.atlassian.com/cloud/trello/guides/rest-api/api-introduction/
# - Get developer API key and create token at top of https://trello.com/app-key
#
key = 'TRELLO-API-KEY-HERE'
token = 'TRELLO-API-TOKEN-HERE'
#
# ------- TRELLO SETTINGS END -------------
arguments = len(sys.argv) - 1
if arguments == 0:
print("=== Trello API Python CLI ===")
print("License: MIT / WeKan Team")
print("See settings in this api.py script for api key and token.")
print("If *nix: chmod +x api.py => ./api.py users")
print("Syntax:")
print(" python3 api.py emoji # List all available emoji")
print(" python3 api.py boards # List All Boards")
print(" python3 api.py board BOARDID # Info of BOARDID")
print(" python3 api.py card CARDID # Info of CARDID")
print(" python3 api.py actions BOARDID # Actions of BOARDID")
print(" python3 api.py reactions ACTIONID # Reactions of ACTIONID")
print(" python3 api.py attachments CARDID # List attachments of CARDID")
print(" python3 api.py download ATTACHMENTURL # Download file from attachment URL like https://.../image.png with streaming and minimal RAM usage")
exit
if arguments == 2:
if sys.argv[1] == 'board':
# ------- BOARD START -----------
#headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
headers = {'Accept': 'application/json'}
boardid = sys.argv[2]
print("=== ONE BOARD ===\n")
listboard = 'https://api.trello.com/1/boards/' + boardid + '?key=' + key + '&token=' + token
body = requests.get(listboard, headers=headers)
data2 = body.text.replace('}',"}\n")
print(data2)
# ------- BOARD END -----------
if sys.argv[1] == 'card':
# ------- CARD START -----------
headers = {'Accept': 'application/json'}
cardid = sys.argv[2]
print("=== ONE CARD ===\n")
listcard = 'https://api.trello.com/1/cards/' + cardid + '?fields=all&key=' + key + '&token=' + token
body = requests.get(listcard, headers=headers)
data2 = body.text.replace('}',"}\n")
print(data2)
# ------- BOARD END -----------
if sys.argv[1] == 'actions':
# ------- BOARD ACTIONS START -----------
headers = {'Accept': 'application/json'}
boardid = sys.argv[2]
print("=== ONE BOARD ACTIONS ===\n")
listboardactions = 'https://api.trello.com/1/boards/' + boardid + '/actions?key=' + key + '&token=' + token
body = requests.get(listboardactions, headers=headers)
data2 = body.text.replace('}',"}\n")
print(data2)
# ------- BOARD ACTIONS END -----------
if sys.argv[1] == 'reactions':
# ------- REACTIONS OF ACTIONID START -----------
headers = {'Accept': 'application/json'}
actionid = sys.argv[2]
print("=== REACTIONS OF ACTIONID ===\n")
listreactions = 'https://api.trello.com/1/actions/' + actionid + '/reactionsSummary?key=' + key + '&token=' + token
body = requests.get(listreactions, headers=headers)
data2 = body.text.replace('}',"}\n")
print(data2)
# ------- REACTIONS OF ACTIONID END -----------
if sys.argv[1] == 'attachments':
# ------- LIST CARD ATTACHMENTS START -----------
headers = {'Accept': 'application/json'}
cardid = sys.argv[2]
print("=== LIST CARD ATTACHMENTS ===\n")
listcardattachments = 'https://api.trello.com/1/cards/' + cardid + '/attachments?key=' + key + '&token=' + token
body = requests.get(listcardattachments, headers=headers)
data2 = body.text.replace('}',"}\n")
print(data2)
# ------- LIST CARD ATTACHMENTS END -----------
if sys.argv[1] == 'download':
# ------- DOWNLOAD BOARD ATTACHMENT START -----------
headers = {'Accept': 'application/json', 'Authorization': 'OAuth oauth_consumer_key="' + key + '", oauth_token="' + token + '"'}
url = sys.argv[2]
print("=== DOWNLOAD BOARD ATTACHMENT ===\n")
local_filename = url.split('/')[-1]
# NOTE the stream=True parameter below. Does streaming download with minimal RAM usage.
with requests.get(url, stream=True, headers=headers) as r:
r.raise_for_status()
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
# If you have chunk encoded response uncomment if
# and set chunk_size parameter to None.
#if chunk:
f.write(chunk)
print("filename: " + local_filename + "\n")
# ------- DOWNLOAD BOARD ATTACHMENT END -----------
if arguments == 1:
if sys.argv[1] == 'boards':
# ------- LIST OF BOARDS START -----------
headers = {'Accept': 'application/json'}
print("=== BOARDS ===\n")
listboards = 'https://api.trello.com/1/members/me/boards?key=' + key + '&token=' + token
body = requests.get(listboards, headers=headers)
data2 = body.text.replace('}',"}\n")
print(data2)
# ------- LIST OF BOARDS END -----------
if sys.argv[1] == 'emoji':
# ------- LIST OF EMOJI START -----------
headers = {'Accept': 'application/json'}
print("=== LIST OF ALL EMOJI ===\n")
listemoji = 'https://api.trello.com/1/emoji?key=' + key + '&token=' + token
body = requests.get(listemoji, headers=headers)
data2 = body.text.replace('}',"}\n")
print(data2)
# ------- LIST OF EMOJI END -----------

File diff suppressed because it is too large Load diff