<p>lynxis lazus has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-ci/+/26393">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">RFC: lint: annotate lines in gerrit<br><br>Use robot comments to add line based comments for the lint output.<br>Add checkpatch_json from coreboot to parse the checkpatch output and<br>convert it into a gerrit parsable format.<br><br>The jenkins nodes needs to access the gerrit via ssh. It might be more<br>secure to put this into a second job.<br><br>Change-Id: I1a48ddb976e0f53bfc0552d0be11e42ba68d9e49<br>---<br>A lint/checkpatch/checkpatch_json.py<br>M lint/lint_diff.sh<br>2 files changed, 66 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-ci refs/changes/93/26393/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/lint/checkpatch/checkpatch_json.py b/lint/checkpatch/checkpatch_json.py</span><br><span>new file mode 100755</span><br><span>index 0000000..c693809</span><br><span>--- /dev/null</span><br><span>+++ b/lint/checkpatch/checkpatch_json.py</span><br><span>@@ -0,0 +1,61 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/usr/bin/env python3</span><br><span style="color: hsl(120, 100%, 40%);">+# SPDX-License-Identifier: GPL-2.0-only</span><br><span style="color: hsl(120, 100%, 40%);">+# from coreboot rev 9cae17d028d4bd3b278fc89ada8e06287917e213</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+"""</span><br><span style="color: hsl(120, 100%, 40%);">+This utilty generate json output to post comment in gerrit.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+INPUT: output of checkpatch.pl.</span><br><span style="color: hsl(120, 100%, 40%);">+OUTPUT: json format output that can be used to post comment in gerrit</span><br><span style="color: hsl(120, 100%, 40%);">+"""</span><br><span style="color: hsl(120, 100%, 40%);">+import os</span><br><span style="color: hsl(120, 100%, 40%);">+import sys</span><br><span style="color: hsl(120, 100%, 40%);">+import json</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+data = {}</span><br><span style="color: hsl(120, 100%, 40%);">+data['comments'] = []</span><br><span style="color: hsl(120, 100%, 40%);">+list_temp = {}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def update_struct( file_path, msg_output, line_number):</span><br><span style="color: hsl(120, 100%, 40%);">+    if file_path not in list_temp:</span><br><span style="color: hsl(120, 100%, 40%);">+        list_temp[file_path] = []</span><br><span style="color: hsl(120, 100%, 40%);">+    list_temp[file_path].append({</span><br><span style="color: hsl(120, 100%, 40%);">+        "robot_id" : "checkpatch",</span><br><span style="color: hsl(120, 100%, 40%);">+        "robot_run_id" : sys.argv[3],</span><br><span style="color: hsl(120, 100%, 40%);">+        "url" : sys.argv[4],</span><br><span style="color: hsl(120, 100%, 40%);">+        "line" : line_number,</span><br><span style="color: hsl(120, 100%, 40%);">+        "message" : msg_output,}</span><br><span style="color: hsl(120, 100%, 40%);">+    )</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def parse_file(input_file):</span><br><span style="color: hsl(120, 100%, 40%);">+    fp = open (input_file, "r")</span><br><span style="color: hsl(120, 100%, 40%);">+    for line in fp:</span><br><span style="color: hsl(120, 100%, 40%);">+        if line.startswith("ERROR:"):</span><br><span style="color: hsl(120, 100%, 40%);">+            msg_output = line.split("ERROR:")[1].strip()</span><br><span style="color: hsl(120, 100%, 40%);">+        elif line.startswith("WARNING:"):</span><br><span style="color: hsl(120, 100%, 40%);">+            msg_output = line.split("WARNING:")[1].strip()</span><br><span style="color: hsl(120, 100%, 40%);">+        elif ": FILE:" in line:</span><br><span style="color: hsl(120, 100%, 40%);">+            temp = line.split("FILE:")</span><br><span style="color: hsl(120, 100%, 40%);">+            file_path = temp[1].split(":")[0]</span><br><span style="color: hsl(120, 100%, 40%);">+            line_number = temp[1].split(":")[1]</span><br><span style="color: hsl(120, 100%, 40%);">+            update_struct( file_path.strip(), msg_output, str(line_number)  )</span><br><span style="color: hsl(120, 100%, 40%);">+        else:</span><br><span style="color: hsl(120, 100%, 40%);">+            continue</span><br><span style="color: hsl(120, 100%, 40%);">+    fp.close()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def main():</span><br><span style="color: hsl(120, 100%, 40%);">+    if (len(sys.argv) < 5) or (sys.argv[1] == "-h"):</span><br><span style="color: hsl(120, 100%, 40%);">+        print("HELP:")</span><br><span style="color: hsl(120, 100%, 40%);">+        print(sys.argv[0] + " <input file> <output file in json> <job-id> <job-url>")</span><br><span style="color: hsl(120, 100%, 40%);">+        sys.exit()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    print(sys.argv[1])</span><br><span style="color: hsl(120, 100%, 40%);">+    parse_file(sys.argv[1])</span><br><span style="color: hsl(120, 100%, 40%);">+    data['robot_comments'] = list_temp</span><br><span style="color: hsl(120, 100%, 40%);">+    print(json.dumps(data))</span><br><span style="color: hsl(120, 100%, 40%);">+    out_file = open( sys.argv[2] , "w")</span><br><span style="color: hsl(120, 100%, 40%);">+    json.dump(data, out_file, sort_keys=True, indent=4)</span><br><span style="color: hsl(120, 100%, 40%);">+    out_file.close()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+if __name__ == "__main__":</span><br><span style="color: hsl(120, 100%, 40%);">+    main()</span><br><span>diff --git a/lint/lint_diff.sh b/lint/lint_diff.sh</span><br><span>index f8daab7..3532454 100755</span><br><span>--- a/lint/lint_diff.sh</span><br><span>+++ b/lint/lint_diff.sh</span><br><span>@@ -31,6 +31,11 @@</span><br><span>     exit 0</span><br><span> fi</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+if ! git diff -U0 "$COMMIT" | "$SCRIPT_DIR/checkpatch/checkpatch_osmo.sh" > gerrit_report ; then</span><br><span style="color: hsl(120, 100%, 40%);">+     "$SCRIPT_DIR/checkpatch/checkpatch_json.py" gerrit_report gerrit_report.json "$BUILD_TAG" "$BUILD_URL"</span><br><span style="color: hsl(120, 100%, 40%);">+  ssh -p "$GERRIT_PORT" -l jenkins "$GERRIT_HOST" gerrit review "$GERRIT_PATCHSET_REVISION" --json < gerrit_report.json</span><br><span style="color: hsl(120, 100%, 40%);">+fi</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> echo</span><br><span> echo "Please fix the linting errors above. More information:"</span><br><span> echo "https://osmocom.org/projects/cellular-infrastructure/wiki/Linting"</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-ci/+/26393">change 26393</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/osmo-ci/+/26393"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-ci </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I1a48ddb976e0f53bfc0552d0be11e42ba68d9e49 </div>
<div style="display:none"> Gerrit-Change-Number: 26393 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: lynxis lazus <lynxis@fe80.eu> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>