Skip to content

ttsukagoshi/Trello_Scripts

Repository files navigation

日本語は後述

Trello Scripts

Google App Scripts to manage Trello using its API and Google Spreadsheet.

Content

  • code.gs: [Required]Primary file with the main codes written. To be used as a spreadsheet-bound script.
  • backup.gs: [Optional]Script to create a full backup of all available Trello boards including actions and attachments. Requires additional authentications as mentioned below.
  • _TrelloScriptLibrary.gs: Code for the Google App Script library Trello Script used in code.gs.

Scope of Authentications (OAuth required for this script)

Additional OAuth Scopes when Using backup.gs

Prepare

  1. Create a new Google Spreadsheet (or use an existing Spreadsheet).
  2. Copy contents of code.gs and common.gs into the spreadsheet using the script editor (Custom Functions in Google Sheets is a good place to start if you don't know what I mean by the script editor) and save the code.
  3. From the script editor, go to File -> Project Properties to set some script properties:
    • trelloKey: API key for Trello
    • trelloToken: API token for Trello
    • boardId: Trello Board Id that you want to manage using the script
      If you're not sure where to find the API keys and tokens for Trello, see API Key Security at the Trello Developers documentation.
  4. Enable TrelloScript Library by entering its script ID 1w2bHQ52dRMv1CG1XR7sW-B4P-A1B6ilaI5n8qNpUFjtJ3RIzla4sAa-Y on Resources -> Library -> Add a Library. The default identifier TrelloScript is used in scripts of code.gs.
  5. Refresh the Google Spreadsheet; you'll see that a menu Trello is added to your menu
  6. You'll be asked for authentications, as mentioned above, when executing the script for the first time.

Functions

  • trelloBoardsLists() (Menu Name: Get My Board): Returns the list of the names and IDs of all Trello boards and its lists available to your account as a new sheet. Useful for getting board IDs for other functions.
  • setTargetBoardId() (Menu Name: Set targetBoardId): Registers the value of the selected cell to script property targetBoardId. Used in trelloReport.
  • trelloDeleteArchivedCards() (Menu Name: Delete Archived Cards): Delete archived cards in a Trello board. Designate board by board ID. USE WITH CARE; CANNOT BE UNDONE!!
  • trelloReport() (Menu Name: Get Board Content): Creates a new sheet on the spreadsheet and list all cards in a Trello board, including archived ones, on it. Designate board by board ID.
  • trelloShowKeyToken() (Menu Name: Key & Token): Shows on an alert window your Trello API key and token registered on your script properties. Useful for making test requests on Trello Developers website.

Variables and Methods in TrelloScript Library

See TrelloScriptLibrary_documentation.md

References


GASとGoogleスプレッドシートを使ってTrelloを管理する。

内容

  • code.gs: [必須]主要なコードが書かれたファイル。スプレッドシートにコンテナバインドされたスクリプトとして使用。
  • backup.gs: [任意]アクセス可能な全てのTrelloボードをGoogle Driveにバックアップするためのスクリプト。
  • _TrelloScriptLibrary.gs: code.gsで使用するGoogle App Scriptライブラリ「Trello Script」のコード

認証のスコープ (このスクリプトを実行するのに必要なOAuth)

backup.gsを使用する際に必要となる追加認証

準備

  1. このスクリプトを利用するための新しいGoogleスプレッドシートを作成する(既存のスプレッドシートでも可)。
  2. code.gsおよびcommon.gsの内容を、スプレッドシートのスクリプトエディタにコピー&ペーストする。「スクリプトエディタ??」という状態なら【初心者向けGAS】本当の最初の一歩!スクリプトエディタでプロジェクトを開くなどがわかりやすい。
  3. スクリプトエディタで、下記スクリプトプロパティを設定する(ファイル -> プロジェクトのプロパティ -> スクリプトのプロパティ):
    • trelloKey: TrelloのAPI key
    • trelloToken: TrelloのAPIトークン
    • boardId: このスクリプトで管理したいTrelloボードのID
      TrelloのAPI keyやトークンについての説明は公式ドキュメントのAPI Key Security参照。
  4. リソース -> ライブラリ -> Add a Libraryに、スクリプトID1w2bHQ52dRMv1CG1XR7sW-B4P-A1B6ilaI5n8qNpUFjtJ3RIzla4sAa-Yを入力することで、ライブラリTrello Scriptを有効にする。最新バージョンを選択。Identifier TrelloScript は初期値のままでok。変更するならば、code.gs内の記述変更を忘れずに。
  5. コードを保存の上、スプレッドシートを更新。メニュー「Trello」が追加されていることを確認すれば準備完了。
  6. スクリプトの初回実行時には、「認証のスコープ」にあるとおりの許可を行う必要がある。

関数

  • trelloBoardsLists() (メニュー名: My Boards & Lists): 自分のアカウントからアクセス可能な全てのTrelloボード及びそのリストの名前とIDを、新しいシートに一覧表として表示。他の関数を実行する際に便利。
  • setTargetBoardId() (メニュー名: Set targetBoardId): 選択したセルのBoard IDを、デフォルトBoard IDとしてスクリプトプロパティtargetBoardIdに登録。trelloReportで反映される。
  • trelloDeleteArchivedCards() (メニュー名: Delete Archived Cards): 指定したTrelloボード内の、アーカイブされたカードを削除する。対象はボードIDで指定。元に戻せないので、実行は要注意!!!
  • trelloReport() (メニュー名: Board Content): 新しいシートを作り、そこに指定したTrelloボード内の全てのカードをリスト化する。アーカイブされたカードも含まれる。対象はボードIDで指定。
  • trelloShowKeyToken() (メニュー名: Key & Token): ポップアップメッセージとして、スクリプトプロパティに設定されたTrello APIキーとトークンを表示させる。公式ドキュメントTrello Developers内で試験リクエストするときに便利。

参考資料