get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/131182/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 131182,
    "url": "https://patches.dpdk.org/api/patches/131182/?format=api",
    "web_url": "https://patches.dpdk.org/project/ci/patch/20230905222317.25821-4-jspewock@iol.unh.edu/",
    "project": {
        "id": 5,
        "url": "https://patches.dpdk.org/api/projects/5/?format=api",
        "name": "CI",
        "link_name": "ci",
        "list_id": "ci.dpdk.org",
        "list_email": "ci@dpdk.org",
        "web_url": "",
        "scm_url": "git://dpdk.org/tools/dpdk-ci",
        "webscm_url": "https://git.dpdk.org/tools/dpdk-ci/",
        "list_archive_url": "https://inbox.dpdk.org/ci",
        "list_archive_url_format": "https://inbox.dpdk.org/ci/{}",
        "commit_url_format": ""
    },
    "msgid": "<20230905222317.25821-4-jspewock@iol.unh.edu>",
    "list_archive_url": "https://inbox.dpdk.org/ci/20230905222317.25821-4-jspewock@iol.unh.edu",
    "date": "2023-09-05T22:13:03",
    "name": "[1/1] tools: add get_reruns script",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "7fb0aabdb272f99b5858fde0ee20f3cf1e92879c",
    "submitter": {
        "id": 2772,
        "url": "https://patches.dpdk.org/api/people/2772/?format=api",
        "name": "Jeremy Spewock",
        "email": "jspewock@iol.unh.edu"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/ci/patch/20230905222317.25821-4-jspewock@iol.unh.edu/mbox/",
    "series": [
        {
            "id": 29430,
            "url": "https://patches.dpdk.org/api/series/29430/?format=api",
            "web_url": "https://patches.dpdk.org/project/ci/list/?series=29430",
            "date": "2023-09-05T22:13:01",
            "name": "tools: Add script for getting rerun requests",
            "version": 1,
            "mbox": "https://patches.dpdk.org/series/29430/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/131182/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/131182/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<ci-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id AFD5E42503;\n\tWed,  6 Sep 2023 00:24:20 +0200 (CEST)",
            "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id B86CD4027C;\n\tWed,  6 Sep 2023 00:24:20 +0200 (CEST)",
            "from mail-qk1-f225.google.com (mail-qk1-f225.google.com\n [209.85.222.225])\n by mails.dpdk.org (Postfix) with ESMTP id 5F5644013F\n for <ci@dpdk.org>; Wed,  6 Sep 2023 00:24:19 +0200 (CEST)",
            "by mail-qk1-f225.google.com with SMTP id\n af79cd13be357-76da22c090dso180307285a.2\n for <ci@dpdk.org>; Tue, 05 Sep 2023 15:24:19 -0700 (PDT)",
            "from postal.iol.unh.edu (postal.iol.unh.edu.\n [2606:4100:3880:1234::84]) by smtp-relay.gmail.com with ESMTPS id\n i7-20020a0cf487000000b0063676c5eb2esm874021qvm.29.2023.09.05.15.24.18\n (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);\n Tue, 05 Sep 2023 15:24:18 -0700 (PDT)",
            "from iol.unh.edu (unknown\n [IPv6:2606:4100:3880:1271:90f9:1b64:f6e6:867f])\n by postal.iol.unh.edu (Postfix) with ESMTP id 5ED106052471;\n Tue,  5 Sep 2023 18:24:18 -0400 (EDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=iol.unh.edu; s=unh-iol; t=1693952659; x=1694557459; darn=dpdk.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=zdoIipl14s5MdVVlSk/5MAEhlZb5RDn6oM+MejVsH0g=;\n b=DY0MzXnhTj0F862Rvj5ecq/6/aNs5Nqd2jlBQnNtw4S5zeRrymp1vxhl0uKzYQg8ES\n /0rKyzEf2weJUj7RXONmNO4txHBTEngiBKlIzWOc5xrM3zU/m/U+3CdR8E0eW7cLJJX6\n jpKumB4Uv3xZVil2f+ForuGx1VzN4x2glWDcA=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20221208; t=1693952659; x=1694557459;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n :subject:date:message-id:reply-to;\n bh=zdoIipl14s5MdVVlSk/5MAEhlZb5RDn6oM+MejVsH0g=;\n b=LF5xUzeWywJYKfYa0d11rh1E4/FkWVDX0ZGI/ynjNVXKhFyEkmJC2noEM88y7/6So3\n n8wU6GtFfG4xdQVB//ejNMO0/2M9/N/CoqIE5alDHqqSdIeuDizntmScA5EWCd/B3QLA\n hCahd2K8YoDS0z504OWkwkK2A8XABAAkDpgYM1Tv070KyGx2+EJXMt2g9Cbfsd83POVy\n E3Ee9Z8pZ102VmQrRN1NCMt6xFcHodLf3v1ffRNGUN7XNKMMMBBTYpdy9vhE3JlhV/Bh\n qfaE4QcljT/cTMRFU31dmFat6EyM2E0QdHcjrs7szFlgFYAnlX+ggIWHGzTdZQaMafUZ\n OaoQ==",
        "X-Gm-Message-State": "AOJu0YxKDnVLdjP/pzN+Yg8BECmMUB49rf7aOvFKxPcrbedLYeCg36M9\n e2T0rAB5wNLVD7nGr9A7WLGc88rCdDiFZOqs8dx9mQYozDyIGNFN8PP4D/vR3aNfnP1eQqv/tSL\n o0QK24cwfRxETtALtHvG9/TERJHbq8X6deK3ZX4IUHxMw6yRfd9MU66myZcpbAYtUqiv4U1Joo1\n t826pe2bFAIcK5iHWUTUW8",
        "X-Google-Smtp-Source": "\n AGHT+IGHbiQop263MCLOHlJLq6lqvTket0giHBReTaXCKNKbXD/2lQMkARx4SqVG/FVuUaPWAXW4aznciuGg",
        "X-Received": "by 2002:a0c:cd0e:0:b0:64f:92d2:44f8 with SMTP id\n b14-20020a0ccd0e000000b0064f92d244f8mr12791020qvm.59.1693952658773;\n Tue, 05 Sep 2023 15:24:18 -0700 (PDT)",
        "X-Relaying-Domain": "iol.unh.edu",
        "From": "jspewock@iol.unh.edu",
        "To": "ci@dpdk.org",
        "Cc": "aconole@redhat.com, alialnu@nvidia.com, probb@iol.unh.edu,\n Jeremy Spewock <jspewock@iol.unh.edu>, Adam Hassick <ahassick@iol.unh.edu>",
        "Subject": "[PATCH 1/1] tools: add get_reruns script",
        "Date": "Tue,  5 Sep 2023 18:13:03 -0400",
        "Message-ID": "<20230905222317.25821-4-jspewock@iol.unh.edu>",
        "X-Mailer": "git-send-email 2.41.0",
        "In-Reply-To": "<20230905222317.25821-2-jspewock@iol.unh.edu>",
        "References": "<20230905222317.25821-2-jspewock@iol.unh.edu>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "ci@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK CI discussions <ci.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/ci>,\n <mailto:ci-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/ci/>",
        "List-Post": "<mailto:ci@dpdk.org>",
        "List-Help": "<mailto:ci-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/ci>,\n <mailto:ci-request@dpdk.org?subject=subscribe>",
        "Errors-To": "ci-bounces@dpdk.org"
    },
    "content": "From: Jeremy Spewock <jspewock@iol.unh.edu>\n\nThis script is used to interact with the DPDK Patchwork API to collect a\nlist of retests from comments on patches based on a desired list of\ncontexts to retest. The script uses regex to scan all of the comments\nsince a timestamp that is passed into the script through the CLI for\nany comment that is requesting a retest. These requests are then filtered\nbased on the desired contexts that you pass into the script through the\nCLI and then aggregated based on the patch series ID of the series that\nthe comment came from. This aggregated list is then outputted to a JSON\nfile with a timestamp of the most recent comment on patchworks.\n\nSigned-off-by: Jeremy Spewock <jspewock@iol.unh.edu>\nSigned-off-by: Adam Hassick <ahassick@iol.unh.edu>\n---\n tools/get_reruns.py | 219 ++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 219 insertions(+)\n create mode 100755 tools/get_reruns.py",
    "diff": "diff --git a/tools/get_reruns.py b/tools/get_reruns.py\nnew file mode 100755\nindex 0000000..159ff6e\n--- /dev/null\n+++ b/tools/get_reruns.py\n@@ -0,0 +1,219 @@\n+#!/usr/bin/env python3\n+# -*- coding: utf-8 -*-\n+# SPDX-License-Identifier: BSD-3-Clause\n+# Copyright(c) 2023 University of New Hampshire\n+\n+import argparse\n+import datetime\n+import json\n+import re\n+from json import JSONEncoder\n+from typing import Dict, List, Set, Optional\n+\n+import requests\n+\n+\n+class JSONSetEncoder(JSONEncoder):\n+    \"\"\"Custom JSON encoder to handle sets.\n+\n+    Pythons json module cannot serialize sets so this custom encoder converts\n+    them into lists.\n+\n+    Args:\n+        JSONEncoder: JSON encoder from the json python module.\n+    \"\"\"\n+\n+    def default(self, input_object):\n+        if isinstance(input_object, set):\n+            return list(input_object)\n+        return input_object\n+\n+\n+class RerunProcessor:\n+    \"\"\"Class for finding reruns inside an email using the patchworks events\n+    API.\n+\n+    The idea of this class is to use regex to find certain patterns that\n+    represent desired contexts to rerun.\n+\n+    Arguments:\n+        desired_contexts: List of all contexts to search for in the bodies of\n+            the comments\n+        time_since: Get all comments since this timestamp\n+\n+    Attributes:\n+        collection_of_retests: A dictionary that maps patch series IDs to the\n+            set of contexts to be retested for that patch series.\n+        regex: regex used for collecting the contexts from the comment body.\n+        last_comment_timestamp: timestamp of the most recent comment that was\n+            processed\n+    \"\"\"\n+\n+    _desired_contexts: List[str]\n+    _time_since: str\n+    collection_of_retests: Dict[str, Dict[str, Set]] = {}\n+    last_comment_timestamp: Optional[str] = None\n+    # ^ is start of line\n+    # ((?:[a-zA-Z-]+(?:, ?\\n?)?)+) is a capture group that gets all test\n+    #   labels after \"Recheck-request: \"\n+    #   (?:[a-zA-Z-]+(?:, ?\\n?)?)+ means 1 or more of the first match group\n+    #       [a-zA-Z0-9-_]+ means 1 more more of any character in the ranges a-z,\n+    #           A-Z, 0-9, or the characters '-' or '_'\n+    #       (?:, ?\\n?)? means 1 or none of this match group which expects\n+    #           exactly 1 comma followed by 1 or no spaces followed by\n+    #           1 or no newlines.\n+    # VALID MATCHES:\n+    #   Recheck-request: iol-unit-testing, iol-something-else, iol-one-more,\n+    #   Recheck-request: iol-unit-testing,iol-something-else, iol-one-more\n+    #   Recheck-request: iol-unit-testing, iol-example, iol-another-example,\n+    #   more-intel-testing\n+    # INVALID MATCHES:\n+    #   Recheck-request: iol-unit-testing,  intel-example-testing\n+    #   Recheck-request: iol-unit-testing iol-something-else,iol-one-more,\n+    #   Recheck-request: iol-unit-testing,iol-something-else,iol-one-more,\n+    #\n+    #   more-intel-testing\n+    regex: str = \"^Recheck-request: ((?:[a-zA-Z0-9-_]+(?:, ?\\n?)?)+)\"\n+\n+    def __init__(self, desired_contexts: List[str], time_since: str) -> None:\n+        self._desired_contexts = desired_contexts\n+        self._time_since = time_since\n+\n+    def process_reruns(self) -> None:\n+        patchwork_url = f\"http://patches.dpdk.org/api/events/?since={self._time_since}\"\n+        comment_request_info = []\n+        for item in [\n+            \"&category=cover-comment-created\",\n+            \"&category=patch-comment-created\",\n+        ]:\n+            response = requests.get(patchwork_url + item)\n+            response.raise_for_status()\n+            comment_request_info.extend(response.json())\n+        rerun_processor.process_comment_info(comment_request_info)\n+\n+    def process_comment_info(self, list_of_comment_blobs: List[Dict]) -> None:\n+        \"\"\"Takes the list of json blobs of comment information and associates\n+        them with their patches.\n+\n+        Collects retest labels from a list of comments on patches represented\n+        inlist_of_comment_blobs and creates a dictionary that associates them\n+        with their corresponding patch series ID. The labels that need to be\n+        retested are collected by passing the comments body into\n+        get_test_names() method. This method also updates the current UTC\n+        timestamp for the processor to the current time.\n+\n+        Args:\n+            list_of_comment_blobs: a list of JSON blobs that represent comment\n+            information\n+        \"\"\"\n+\n+        list_of_comment_blobs = sorted(\n+            list_of_comment_blobs,\n+            key=lambda x: datetime.datetime.fromisoformat(x[\"date\"]),\n+            reverse=True,\n+        )\n+\n+        if list_of_comment_blobs:\n+            most_recent_timestamp = datetime.datetime.fromisoformat(\n+                list_of_comment_blobs[0][\"date\"]\n+            )\n+            # exclude the most recent\n+            most_recent_timestamp = most_recent_timestamp + datetime.timedelta(\n+                microseconds=1\n+            )\n+            self.last_comment_timestamp = most_recent_timestamp.isoformat()\n+\n+        for comment in list_of_comment_blobs:\n+            # before we do any parsing we want to make sure that we are dealing\n+            # with a comment that is associated with a patch series\n+            payload_key = \"cover\"\n+            if comment[\"category\"] == \"patch-comment-created\":\n+                payload_key = \"patch\"\n+            patch_series_arr = requests.get(\n+                comment[\"payload\"][payload_key][\"url\"]\n+            ).json()[\"series\"]\n+            if not patch_series_arr:\n+                continue\n+            patch_id = patch_series_arr[0][\"id\"]\n+\n+            comment_info = requests.get(comment[\"payload\"][\"comment\"][\"url\"])\n+            comment_info.raise_for_status()\n+            content = comment_info.json()[\"content\"]\n+\n+            labels_to_rerun = self.get_test_names(content)\n+\n+            # appending to the list if it already exists, or creating it if it\n+            # doesn't\n+            if labels_to_rerun:\n+                self.collection_of_retests[patch_id] = self.collection_of_retests.get(\n+                    patch_id, {\"contexts\": set()}\n+                )\n+                self.collection_of_retests[patch_id][\"contexts\"].update(labels_to_rerun)\n+\n+    def get_test_names(self, email_body: str) -> Set[str]:\n+        \"\"\"Uses the regex in the class to get the information from the email.\n+\n+        When it gets the test names from the email, it will all be in one\n+        capture group. We expect a comma separated list of patchwork labels\n+        to be retested.\n+\n+        Returns:\n+            A set of contexts found in the email that match your list of\n+            desired contexts to capture. We use a set here to avoid duplicate\n+            contexts.\n+        \"\"\"\n+        rerun_section = re.findall(self.regex, email_body, re.MULTILINE)\n+        if not rerun_section:\n+            return set()\n+        rerun_list = list(map(str.strip, rerun_section[0].split(\",\")))\n+        return set(filter(lambda x: x and x in self._desired_contexts, rerun_list))\n+\n+    def write_to_output_file(self, file_name: str) -> None:\n+        \"\"\"Write class information to a JSON file.\n+\n+        Takes the collection_of_retests and last_comment_timestamp and outputs\n+        them into a json file.\n+\n+        Args:\n+            file_name: Name of the file to write the output to.\n+        \"\"\"\n+\n+        output_dict = {\n+            \"retests\": self.collection_of_retests,\n+            \"last_comment_timestamp\": self.last_comment_timestamp,\n+        }\n+        with open(file_name, \"w\") as file:\n+            file.write(json.dumps(output_dict, indent=4, cls=JSONSetEncoder))\n+\n+\n+if __name__ == \"__main__\":\n+    parser = argparse.ArgumentParser(description=\"Help text for getting reruns\")\n+    parser.add_argument(\n+        \"-ts\",\n+        \"--time-since\",\n+        dest=\"time_since\",\n+        required=True,\n+        help=\"Get all patches since this many days ago (default: 5)\",\n+    )\n+    parser.add_argument(\n+        \"--contexts\",\n+        dest=\"contexts_to_capture\",\n+        nargs=\"*\",\n+        required=True,\n+        help=\"List of patchwork contexts you would like to capture\",\n+    )\n+    parser.add_argument(\n+        \"-o\",\n+        \"--out-file\",\n+        dest=\"out_file\",\n+        help=(\n+            \"Output file where the list of reruns and the timestamp of the\"\n+            \"last comment in the list of comments\"\n+            \"(default: rerun_requests.json).\"\n+        ),\n+        default=\"rerun_requests.json\",\n+    )\n+    args = parser.parse_args()\n+    rerun_processor = RerunProcessor(args.contexts_to_capture, args.time_since)\n+    rerun_processor.process_reruns()\n+    rerun_processor.write_to_output_file(args.out_file)\n",
    "prefixes": [
        "1/1"
    ]
}