Skip to content

Commit 43f3715

Browse files
committed
fix: robust labeler args; dedupe/append people; correct cartopy transform
- utilities/labeler: make changed_files optional, fix variable name (issueNum), guard matchList arg access, replace toInt with strconv.Atoi - Kubestronaut/CNCFInsertKubestronautInPeople_json.py: prevent duplicates, insert once, and write sorted output - Ambassadors/CNCFInsertAmbassadorInPeople_json.py: append when new name sorts after all existing entries - Rendering/GenerateWorldTimelapseCartopy.py: use PlateCarree transform; guard basemap call to avoid runtime errors Signed-off-by: Shubham Shukla <shubhushukla586@gmail.com>
1 parent db5d055 commit 43f3715

File tree

4 files changed

+38
-21
lines changed

4 files changed

+38
-21
lines changed

Ambassadors/CNCFInsertAmbassadorInPeople_json.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ def process_entries(firstLine, lastLine):
279279

280280
# Insert new person in sorted order
281281
indexPeople = 0
282+
inserted = False
282283
for people in data:
283284
if people["name"].lower() < newPerson.name.lower():
284285
indexPeople += 1
@@ -290,8 +291,15 @@ def process_entries(firstLine, lastLine):
290291
data.insert(indexPeople, json.JSONDecoder(object_pairs_hook=OrderedDict).decode(newPerson.toJSON()))
291292
split_tup = os.path.splitext(newPerson.image)
292293
os.rename("imageTemp" + split_tup[1], "../../people/images/" + newPerson.image)
294+
inserted = True
293295
break
294296

297+
if not inserted:
298+
# Append to end if new name sorts after all existing entries
299+
data.append(json.JSONDecoder(object_pairs_hook=OrderedDict).decode(newPerson.toJSON()))
300+
split_tup = os.path.splitext(newPerson.image)
301+
os.rename("imageTemp" + split_tup[1], "../../people/images/" + newPerson.image)
302+
295303
# Write updated data back to file
296304
with open(PEOPLE_JSON_PATH, "w", encoding='utf-8') as jsonfile:
297305
json.dump(data, jsonfile, indent=3, ensure_ascii=False, sort_keys=False)

Kubestronaut/CNCFInsertKubestronautInPeople_json.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,22 +176,20 @@ def ack_kubestronaut(email):
176176
if (peopleFound == True) :
177177
print(newPeople.toJSON())
178178

179-
indexPeople=0
180-
for people in data:
181-
if people["name"].lower() == newPeople.name.lower():
182-
print("{newPeople.name} already in people.json, abort !")
183-
exit(2)
184-
else:
185-
print('Adding '+newPeople.name)
186-
data.insert(0, json.JSONDecoder(object_pairs_hook=OrderedDict).decode(newPeople.toJSON()))
187-
os.rename("imageTemp.jpg", "../../people/images/"+newPeople.image)
188-
ack_kubestronaut(row[12])
189-
break
179+
# Check for existing entry first; add only if not present
180+
if any(p["name"].lower() == newPeople.name.lower() for p in data):
181+
print(f"{newPeople.name} already in people.json, abort !")
182+
exit(2)
183+
184+
print('Adding ' + newPeople.name)
185+
data.insert(0, json.JSONDecoder(object_pairs_hook=OrderedDict).decode(newPeople.toJSON()))
186+
os.rename("imageTemp.jpg", "../../people/images/" + newPeople.image)
187+
ack_kubestronaut(row[12])
190188

191189
sorted_people = sorted(data, key=lambda x: x['name'])
192190

193191
with open('../../people/people.json', "w", encoding='utf-8') as jsonfile:
194-
jsonfile.write(json.dumps(data, indent=4, ensure_ascii=False))
192+
jsonfile.write(json.dumps(sorted_people, indent=4, ensure_ascii=False))
195193

196194
if NON_acked_Kubestronauts:
197195
print("\n\nList of Kubestroauts that were NOT ACKED:")

Kubestronaut/Rendering/GenerateWorldTimelapseCartopy.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@ def color_country(country):
6969
world['color'] = world['ADMIN'].apply(color_country)
7070

7171
# Plot the countries with the specified color
72-
world.plot(ax=ax, color=world['color'], edgecolor='black', transform=ccrs.Robinson(), alpha=0.8)
72+
world.plot(ax=ax, color=world['color'], edgecolor='black', transform=ccrs.PlateCarree(), alpha=0.8)
7373

74-
# Add the OpenStreetMap basemap underneath the countries to give depth
75-
cx.add_basemap(ax, crs=ccrs.Robinson().proj4_init, source=cx.providers.OpenStreetMap.Mapnik)
74+
# Try to add a basemap for context; if unavailable, continue without it
75+
try:
76+
cx.add_basemap(ax, source=cx.providers.OpenStreetMap.Mapnik)
77+
except Exception:
78+
pass
7679

7780
# Clear any previous text to avoid overlap and re-render fresh text
7881
fig.texts.clear()

utilities/labeler/main.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"path/filepath"
1111
"slices"
12+
"strconv"
1213
"strings"
1314

1415
"github.com/google/go-github/v55/github"
@@ -95,15 +96,18 @@ func main() {
9596
flag.Parse()
9697

9798
if len(flag.Args()) < 5 {
98-
fmt.Println("Usage: labeler [flags] <labels_url> <owner> <repo> <issue_number> <comment_body> <changed_files>")
99+
fmt.Println("Usage: labeler [flags] <labels_url> <owner> <repo> <issue_number> <comment_body> [changed_files]")
99100
os.Exit(1)
100101
}
101102
labelsURL := flag.Arg(0)
102103
owner := flag.Arg(1)
103104
repo := flag.Arg(2)
104105
issueNum := flag.Arg(3)
105106
commentBody := flag.Arg(4)
106-
changedFiles := flag.Arg(5)
107+
var changedFiles string
108+
if len(flag.Args()) >= 6 {
109+
changedFiles = flag.Arg(5)
110+
}
107111

108112
if labelsURL == "" {
109113
log.Fatal("labels URL not set")
@@ -210,6 +214,12 @@ func main() {
210214
*/
211215
if len(rule.Spec.MatchList) > 0 {
212216
// Validate argv.0 against matchList
217+
if len(argv) == 0 {
218+
if cfg.Debug {
219+
log.Printf("No argument provided for command %s to validate against matchList", rule.Spec.Command)
220+
}
221+
continue
222+
}
213223
valid := slices.Contains(rule.Spec.MatchList, argv[0])
214224
if !valid {
215225
log.Printf("Invalid argument `%s` for command %s", argv[0], rule.Spec.Command)
@@ -453,11 +463,9 @@ func removeLabel(ctx context.Context, client *github.Client, owner, repo string,
453463
}
454464

455465
func toInt(s string) int {
456-
n, err := fmt.Sscanf(s, "%d", new(int))
457-
if err != nil || n != 1 {
466+
i, err := strconv.Atoi(strings.TrimSpace(s))
467+
if err != nil {
458468
log.Fatalf("invalid issue number: %s", s)
459469
}
460-
var i int
461-
fmt.Sscanf(s, "%d", &i)
462470
return i
463471
}

0 commit comments

Comments
 (0)