Skip to content

Commit 669c8b5

Browse files
committed
fix: resolve comments
Signed-off-by: matttrach <matt.trachier@suse.com>
1 parent 3e80ffb commit 669c8b5

7 files changed

Lines changed: 46 additions & 16 deletions

File tree

get-pr-comments.sh

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
14
# This gets all of the comments for a PR, helpful when writing with an agent.
25
# Expects your environment to have GITHUB_TOKEN with a PAT that can access the API.
6+
7+
if [ -z "${GITHUB_TOKEN:-}" ]; then
8+
echo "Error: GITHUB_TOKEN environment variable is not set." >&2
9+
exit 1
10+
fi
11+
12+
if ! command -v jq >/dev/null 2>&1; then
13+
echo "Error: jq is required but not installed." >&2
14+
exit 1
15+
fi
16+
317
PROJECT="rancher/terraform-rancher2-aws"
4-
PULL_ID=$1
18+
PULL_ID=${1:-}
19+
20+
if [ -z "$PULL_ID" ]; then
21+
echo "Error: PR ID argument is required." >&2
22+
echo "Usage: $0 <pr-id>" >&2
23+
exit 1
24+
fi
25+
26+
OWNER=$(echo "$PROJECT" | cut -d/ -f1)
27+
REPO=$(echo "$PROJECT" | cut -d/ -f2)
28+
29+
# The GitHub REST API doesn't expose resolution status. We switch to GraphQL to filter by 'isResolved'.
30+
JSON_PAYLOAD=$(jq -n \
31+
--arg q 'query($owner: String!, $name: String!, $pr: Int!) { repository(owner: $owner, name: $name) { pullRequest(number: $pr) { reviewThreads(first: 100) { nodes { isResolved comments(first: 50) { nodes { path line diffHunk body } } } } } } }' \
32+
--arg owner "$OWNER" \
33+
--arg name "$REPO" \
34+
--argjson pr "${PULL_ID:-0}" \
35+
'{ query: $q, variables: { owner: $owner, name: $name, pr: $pr } }')
36+
537
curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
6-
-H "Accept: application/vnd.github+json" \
7-
"https://api.github.com/repos/$PROJECT/pulls/${PULL_ID}/comments" | \
8-
jq -r '.[] | "File: \(.path)\nLine: \(.line)\nDiff:\n\(.diff_hunk)\n\nComment:\n\(.body)\n\n========================================\n"'
38+
-X POST -d "$JSON_PAYLOAD" \
39+
"https://api.github.com/graphql" | \
40+
jq -r '.data.repository.pullRequest.reviewThreads.nodes[]? | select(.isResolved == false) | .comments.nodes[]? | "File: \(.path)\nLine: \(.line)\nDiff:\n\(.diffHunk)\n\nComment:\n\(.body)\n\n========================================\n"'

main.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ resource "terraform_data" "input_validation" {
7575
))
7676
error_message = "The fqdn must be a fully qualified domain name"
7777
}
78-
precondition {
79-
condition = local.fqdn == lower(local.fqdn)
80-
error_message = "fqdn must be lowercase"
81-
}
8278
precondition {
8379
condition = (
8480
local.rancher_helm_chart_values != {} &&

modules/deploy/create.sh.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ trap 'cleanup' INT TERM
1919
# Handle age decryption if needed
2020
SECRETS_DECRYPTED=0
2121
if [ -n "$AGE_KEY_PATH" ] && [ -n "$SECRETS_PATH" ] && [ -f "$AGE_KEY_PATH" ] && [ -f "$SECRETS_PATH" ]; then
22-
DECRYPTED_SECRETS="/tmp/secrets.rc"
22+
DECRYPTED_SECRETS=$(mktemp /tmp/secrets.XXXXXX)
2323
echo "Decrypting secrets with age..."
2424

2525
age -d -i "$AGE_KEY_PATH" -o "$DECRYPTED_SECRETS" "$SECRETS_PATH"
2626
if [ -f "$DECRYPTED_SECRETS" ]; then
27-
chmod +x "$DECRYPTED_SECRETS"
27+
chmod 0600 "$DECRYPTED_SECRETS"
2828
# shellcheck disable=SC1090
2929
. "$DECRYPTED_SECRETS"
3030
SECRETS_DECRYPTED=1

modules/deploy/destroy.sh.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ trap 'cleanup' INT TERM
1717
# Handle age decryption if needed
1818
SECRETS_DECRYPTED=0
1919
if [ -n "$AGE_KEY_PATH" ] && [ -n "$SECRETS_PATH" ] && [ -f "$AGE_KEY_PATH" ] && [ -f "$SECRETS_PATH" ]; then
20-
DECRYPTED_SECRETS="/tmp/secrets.rc"
20+
DECRYPTED_SECRETS=$(mktemp /tmp/secrets.XXXXXX)
2121
echo "Decrypting secrets with age..."
2222

2323
age -d -i "$AGE_KEY_PATH" -o "$DECRYPTED_SECRETS" "$SECRETS_PATH"
2424
if [ -f "$DECRYPTED_SECRETS" ]; then
25-
chmod +x "$DECRYPTED_SECRETS"
25+
chmod 0600 "$DECRYPTED_SECRETS"
2626
# shellcheck disable=SC1090
2727
. "$DECRYPTED_SECRETS"
2828
SECRETS_DECRYPTED=1

modules/deploy/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ resource "file_local" "instantiate_tpl_snapshot" {
103103
file_local_snapshot.persist_tpl_file,
104104
]
105105
for_each = local.template_file_map
106-
directory = "${local.deploy_path}/${replace(dirname(each.key), ".", "")}"
107-
name = basename(each.value)
106+
directory = dirname("${local.deploy_path}/${each.key}")
107+
name = basename(each.key)
108108
permissions = data.file_local.template_files[each.key].permissions
109109
contents = base64decode(file_local_snapshot.persist_tpl_file[each.key].snapshot)
110110
}
@@ -191,7 +191,7 @@ resource "file_local" "generate_files" {
191191
file_local_directory.template_dirs,
192192
]
193193
for_each = local.generated_files
194-
directory = "${local.deploy_path}/${replace(dirname(each.key), ".", "")}"
194+
directory = dirname("${local.deploy_path}/${each.key}")
195195
name = basename(each.key)
196196
contents = each.value
197197
permissions = "0755"

modules/deploy/variables.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ variable "inputs" {
33
description = <<-EOT
44
Contents of an inputs.tfvars file to save in the deployment path.
55
EOT
6+
default = ""
67
}
78
variable "template_files" {
89
type = map(any)
@@ -31,6 +32,7 @@ variable "data_path" {
3132
Should match your TF_DATA_DIR environment variable.
3233
This directory is used to stage all of the various files for your implementation.
3334
EOT
35+
default = null
3436
}
3537
variable "plugin_cache_path" {
3638
type = string

test/scripts/readyNodes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ notReady() {
4040
TIMEOUT=3 # 3 minutes
4141
TIMEOUT_MINUTES=$((TIMEOUT * 60))
4242
INTERVAL=10 # 10 seconds
43-
MAX=$((TIMEOUT_MINUTES / INTERVAL)) # defaults to 6
43+
MAX=$((TIMEOUT_MINUTES / INTERVAL)) # defaults to 18
4444
ATTEMPTS=0
4545

4646
while notReady; do

0 commit comments

Comments
 (0)