Skip to content

Commit 669a342

Browse files
LeSuisseHyzual
authored andcommitted
1 parent dbf9477 commit 669a342

15 files changed

Lines changed: 183 additions & 92 deletions

File tree

.github/workflows/CI.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Tests
22

3-
permissions: read-all
3+
permissions: {}
44

55
on:
66
push:
@@ -16,17 +16,30 @@ jobs:
1616
- "artifact-post-action/auto-assign"
1717
- "artifact-post-action/compute-risk"
1818
- "artifact-post-action/post-action-add-comment"
19-
runs-on: ubuntu-22.04
19+
runs-on: ubuntu-24.04
2020
name: Tests (${{ matrix.tuleap_functions }})
2121
defaults:
2222
run:
2323
working-directory: ${{ matrix.tuleap_functions }}
2424
steps:
25-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26-
- uses: cachix/install-nix-action@3715ab1a11cac9e991980d7b4a28d80c7ebdd8f9 # v27
25+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
26+
with:
27+
persist-credentials: false
28+
- uses: cachix/install-nix-action@fd24c48048070c1be9acd18c9d369a83f0fe94d7 # v31.8.1
2729
- name: Prepare
2830
run: nix-shell --run "make prepare"
2931
- name: Tests
3032
run: nix-shell --pure --run "make tests"
3133
- name: Build
3234
run: nix-shell --pure --run "make build"
35+
formatting_linting:
36+
name: Check for formatting or linting issues
37+
runs-on: ubuntu-24.04
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
41+
with:
42+
persist-credentials: false
43+
- uses: cachix/install-nix-action@fd24c48048070c1be9acd18c9d369a83f0fe94d7 # v31.8.1
44+
- name: Build
45+
run: nix-shell --pure --run 'treefmt --ci'

artifact-post-action/auto-assign/javy.nix

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# TODO:
22
# * build from sources
33
# * upstream to nixpkgs
4-
{ stdenv
5-
, lib
6-
, fetchurl
7-
, autoPatchelfHook
8-
, gzip
4+
{
5+
stdenv,
6+
lib,
7+
fetchurl,
8+
autoPatchelfHook,
9+
gzip,
910
}:
1011

1112
stdenv.mkDerivation rec {
@@ -25,7 +26,7 @@ stdenv.mkDerivation rec {
2526
buildInputs = [
2627
stdenv.cc.cc.lib
2728
];
28-
29+
2930
unpackPhase = ''
3031
runHook preUnpack
3132
gzip -cd "${src}" > javy

artifact-post-action/auto-assign/shell.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
{ pkgs ? (import ../tools/pinned-nixpkgs.nix) {} }:
1+
{
2+
pkgs ? (import ../../build-support/pinned-nixpkgs.nix) { },
3+
}:
24

35
pkgs.mkShellNoCC {
46
buildInputs = [

artifact-post-action/compute-risk-and-residual/shell.nix

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
{ pkgs ? (import ./../tools/pinned-nixpkgs.nix) {} }:
1+
{
2+
pkgs ? (import ./../../build-support/pinned-nixpkgs.nix) { },
3+
}:
24

35
pkgs.mkShellNoCC {
46
buildInputs = [
57
(pkgs.rust-bin.stable.latest.default.override {
68
targets = [ "wasm32-wasip1" ];
7-
extensions = [ "cargo" "rustc" "rust-src" ];
9+
extensions = [
10+
"cargo"
11+
"rustc"
12+
"rust-src"
13+
];
814
})
915
pkgs.gnumake
1016
];

artifact-post-action/compute-risk-and-residual/src/main.rs

Lines changed: 69 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
use serde::{Serialize, Deserialize};
24+
use serde::{Deserialize, Serialize};
2525
use serde_json::json;
2626
use std::error::Error;
2727
use std::io::stdin;
@@ -51,17 +51,11 @@ enum ListValue {
5151
#[serde(tag = "type")]
5252
enum FieldValue {
5353
#[serde(rename = "string")]
54-
String {
55-
field_id: u32,
56-
},
54+
String { field_id: u32 },
5755
#[serde(rename = "text")]
58-
Text {
59-
field_id: u32,
60-
},
56+
Text { field_id: u32 },
6157
#[serde(rename = "art_link")]
62-
Link {
63-
field_id: u32,
64-
},
58+
Link { field_id: u32 },
6559
#[serde(rename = "sb")]
6660
SelectBox {
6761
field_id: u32,
@@ -70,15 +64,9 @@ enum FieldValue {
7064
bind_value_ids: Vec<u32>,
7165
},
7266
#[serde(rename = "aid")]
73-
ArtifactId {
74-
field_id: u32,
75-
label: String,
76-
},
67+
ArtifactId { field_id: u32, label: String },
7768
#[serde(rename = "rb")]
78-
RadioButton {
79-
field_id: u32,
80-
label: String,
81-
},
69+
RadioButton { field_id: u32, label: String },
8270
}
8371

8472
#[derive(Serialize, Deserialize)]
@@ -103,7 +91,7 @@ struct TrackerField {
10391
#[derive(Serialize, Deserialize)]
10492
struct Tracker {
10593
id: u32,
106-
fields: Vec<TrackerField>
94+
fields: Vec<TrackerField>,
10795
}
10896

10997
#[derive(Serialize, Deserialize)]
@@ -120,32 +108,51 @@ fn convert_label_to_integer(label: String) -> Result<u32, Box<dyn Error>> {
120108
}
121109
}
122110

123-
fn find_select_box_by_label<'a>(changeset: &'a Changeset, target_label: &str) -> Option<&'a FieldValue> {
124-
changeset.values.iter().find(|field_value| match field_value {
125-
FieldValue::SelectBox { label, .. } if label == target_label => true,
126-
_ => false,
127-
})
111+
fn find_select_box_by_label<'a>(
112+
changeset: &'a Changeset,
113+
target_label: &str,
114+
) -> Option<&'a FieldValue> {
115+
changeset
116+
.values
117+
.iter()
118+
.find(|field_value| match field_value {
119+
FieldValue::SelectBox { label, .. } if label == target_label => true,
120+
_ => false,
121+
})
128122
}
129123

130124
fn find_value_matching_label(field_value: &FieldValue) -> Option<String> {
131125
match field_value {
132-
FieldValue::SelectBox { values, .. } => values.first().and_then(|first_value| match first_value {
133-
ListValue::StaticValue { label, .. } => Some(label.to_string()),
134-
_ => None,
135-
}),
126+
FieldValue::SelectBox { values, .. } => {
127+
values.first().and_then(|first_value| match first_value {
128+
ListValue::StaticValue { label, .. } => Some(label.to_string()),
129+
_ => None,
130+
})
131+
}
136132
_ => None,
137133
}
138134
}
139135

140-
fn find_select_box_value_by_label(artifact: &Artifact, target_label: &str) -> Result<Option<u32>, Box<dyn Error>> {
136+
fn find_select_box_value_by_label(
137+
artifact: &Artifact,
138+
target_label: &str,
139+
) -> Result<Option<u32>, Box<dyn Error>> {
141140
find_select_box_by_label(&artifact.current, target_label)
142-
.and_then(|field_value| find_value_matching_label(field_value) )
143-
.and_then(|label| Some(convert_label_to_integer(label)))
144-
.transpose()
141+
.and_then(|field_value| find_value_matching_label(field_value))
142+
.and_then(|label| Some(convert_label_to_integer(label)))
143+
.transpose()
145144
}
146145

147-
fn find_risk_value(artifact: &Artifact, risk_field_label: &str, product: u32) -> Result<Option<FieldValueBinding>, Box<dyn Error>> {
148-
let risk_field_option = artifact.tracker.fields.iter().find(|field| field.label == risk_field_label);
146+
fn find_risk_value(
147+
artifact: &Artifact,
148+
risk_field_label: &str,
149+
product: u32,
150+
) -> Result<Option<FieldValueBinding>, Box<dyn Error>> {
151+
let risk_field_option = artifact
152+
.tracker
153+
.fields
154+
.iter()
155+
.find(|field| field.label == risk_field_label);
149156

150157
if risk_field_option.is_none() {
151158
return Err(format!("Cannot find field {}", risk_field_label).into());
@@ -157,10 +164,9 @@ fn find_risk_value(artifact: &Artifact, risk_field_label: &str, product: u32) ->
157164
}
158165
let risk_values = risk_field.values.as_ref().unwrap();
159166

160-
let matching_value = risk_values.iter()
161-
.find(|value| {
162-
value.label.as_str() == product.to_string()
163-
});
167+
let matching_value = risk_values
168+
.iter()
169+
.find(|value| value.label.as_str() == product.to_string());
164170

165171
if let Some(matching_value) = matching_value {
166172
Ok(Some(FieldValueBinding {
@@ -172,7 +178,12 @@ fn find_risk_value(artifact: &Artifact, risk_field_label: &str, product: u32) ->
172178
}
173179
}
174180

175-
fn process_risk_values(artifact: &Artifact, severity_field_label: &str, probability_field_label: &str, risk_field_label: &str) -> Result<Option<FieldValueBinding>, Box<dyn Error>> {
181+
fn process_risk_values(
182+
artifact: &Artifact,
183+
severity_field_label: &str,
184+
probability_field_label: &str,
185+
risk_field_label: &str,
186+
) -> Result<Option<FieldValueBinding>, Box<dyn Error>> {
176187
let severity = find_select_box_value_by_label(&artifact, severity_field_label)?;
177188
if severity.is_none() {
178189
return Ok(None);
@@ -184,7 +195,7 @@ fn process_risk_values(artifact: &Artifact, severity_field_label: &str, probabil
184195
return Ok(None);
185196
}
186197
let probability_value = probability.unwrap();
187-
198+
188199
let product = severity_value * probability_value;
189200

190201
find_risk_value(artifact, risk_field_label, product)
@@ -198,26 +209,30 @@ fn main() -> Result<(), Box<dyn Error>> {
198209

199210
let mut bindings: Vec<FieldValueBinding> = Vec::new();
200211
match process_risk_values(&artifact, "Severity", "Probability", "Risk") {
201-
Ok(possible_binding) => {
202-
match possible_binding {
203-
Some(binding) => bindings.push(binding),
204-
None => ()
205-
}
212+
Ok(possible_binding) => match possible_binding {
213+
Some(binding) => bindings.push(binding),
214+
None => (),
206215
},
207216
Err(e) => return Err(e),
208217
}
209-
match process_risk_values(&artifact, "Residual severity", "Residual probability", "Residual risk level") {
210-
Ok(possible_binding) => {
211-
match possible_binding {
212-
Some(binding) => bindings.push(binding),
213-
None => ()
214-
}
218+
match process_risk_values(
219+
&artifact,
220+
"Residual severity",
221+
"Residual probability",
222+
"Residual risk level",
223+
) {
224+
Ok(possible_binding) => match possible_binding {
225+
Some(binding) => bindings.push(binding),
226+
None => (),
215227
},
216228
Err(e) => return Err(e),
217229
}
218-
println!("{}", json!({
219-
"values": bindings
220-
}));
230+
println!(
231+
"{}",
232+
json!({
233+
"values": bindings
234+
})
235+
);
221236

222237
Ok(())
223238
}

artifact-post-action/compute-risk/shell.nix

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
{ pkgs ? (import ../tools/pinned-nixpkgs.nix) {} }:
1+
{
2+
pkgs ? (import ../../build-support/pinned-nixpkgs.nix) { },
3+
}:
24

35
pkgs.mkShellNoCC {
46
buildInputs = [
57
(pkgs.rust-bin.stable.latest.default.override {
68
targets = [ "wasm32-wasip1" ];
7-
extensions = [ "cargo" "rustc" "rust-src" ];
9+
extensions = [
10+
"cargo"
11+
"rustc"
12+
"rust-src"
13+
];
814
})
915
pkgs.gnumake
1016
];

artifact-post-action/compute-risk/src/main.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
use serde_json::{json, Value};
24+
use serde_json::{Value, json};
2525
use std::error::Error;
2626
use std::io::stdin;
2727

@@ -63,11 +63,7 @@ fn main() -> Result<(), Box<dyn Error>> {
6363

6464
let field_risk = json["tracker"]["fields"]
6565
.as_array()
66-
.and_then(|fields| {
67-
fields
68-
.iter()
69-
.find(|&field| field["label"] == "Risk")
70-
});
66+
.and_then(|fields| fields.iter().find(|&field| field["label"] == "Risk"));
7167

7268
if field_risk.is_none() {
7369
return Err("Cannot find field_risk")?;
@@ -79,25 +75,30 @@ fn main() -> Result<(), Box<dyn Error>> {
7975
return Err("Cannot find Risk values")?;
8076
}
8177

82-
if let (Some(severity_value), Some(probability_value)) = (field_severity_value, field_probability_value) {
78+
if let (Some(severity_value), Some(probability_value)) =
79+
(field_severity_value, field_probability_value)
80+
{
8381
let product = severity_value * probability_value;
8482

85-
let matching_value = risk_values.unwrap().into_iter()
86-
.find(|&value| {
83+
let matching_value = risk_values.unwrap().into_iter().find(|&value| {
8784
let value_label = value["label"].as_str().unwrap_or_default();
8885
value_label == product.to_string()
8986
});
9087

9188
if let Some(matching_value) = matching_value {
9289
let field_id = field_risk.unwrap()["field_id"].as_i64().unwrap_or(0);
93-
println!("{}", json!({
94-
"values": [{
95-
"field_id": field_id,
96-
"bind_value_ids": [
97-
matching_value["id"]
98-
]
99-
}]
100-
}).to_string());
90+
println!(
91+
"{}",
92+
json!({
93+
"values": [{
94+
"field_id": field_id,
95+
"bind_value_ids": [
96+
matching_value["id"]
97+
]
98+
}]
99+
})
100+
.to_string()
101+
);
101102

102103
Ok(())
103104
} else {

0 commit comments

Comments
 (0)