Find what automation rules contain certain values (i.e. custom fields) using Python

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問


 

プラットフォームについて: Cloud のみ - この記事は クラウド プラットフォームのアトラシアン製品に適用されます。

   


免責事項

Atlassian does not support this code below, which is provided "AS IS". The goal of this article is to provide a piece of code that illustrates one way to achieve the desired goal.

Feedback provided at the bottom of the page is appreciated, but won't be handled as support.

要約

The Python script on this page searches across a JSON from the automation rule export. If the inserted value is present in your JSON file, it will return the position within the JSON and the automation rule name and state (enabled/disabled).


環境

Jira Cloud

This script requires Python 3 to be installed.


用途

  1. Export all your automation rules to JSON following this article.

  2. Ensure the script and the JSON file are in the same folder structure.

  3. Run the script. You’ll be prompted with the value to search for and the JSON file name (remember the .json file extension).

  4. The results will be shown in the console.


スクリプト
import json
def find_value(json_obj, value, path="", parent_name=None, parent_state=None):
    if isinstance(json_obj, dict):
        if "name" in json_obj and "state" in json_obj:
            parent_name = json_obj["name"]
            parent_state = json_obj["state"]
        for key, val in json_obj.items():
            new_path = f"{path}.{key}" if path else key
            if isinstance(val, list) or isinstance(val, dict):
                find_value(val, value, new_path, parent_name, parent_state)
            elif isinstance(val, str) and value in val:
                print(f"Found '{value}' at {new_path}")
                print(f"Name: {parent_name}")
                print(f"State: {parent_state}")
    elif isinstance(json_obj, list):
        for i, item in enumerate(json_obj):
            new_path = f"{path}[{i}]"
            find_value(item, value, new_path, parent_name, parent_state)
# Manually input the value to search for
search_value = input("Enter the value to search for: ")
# Manually input the JSON file name
json_file_name = input("Enter the JSON file name: ")
print(f"Searching for '{search_value}' in the JSON {json_file_name}")
# Load JSON data from a file
with open(json_file_name) as json_file:
    data = json.load(json_file)
find_value(data, search_value)

Practical example: 



最終更新日 2024 年 7 月 12 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.