Skip to content

Commit 49311ab

Browse files
Merge pull request #9 from gregorriegler/session-note-cleanup
session-note cleanup (via ChatGPT generated code)
2 parents b03bc8a + 2d077a0 commit 49311ab

File tree

58 files changed

+374
-380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+374
-380
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
use strict;
2+
use warnings;
3+
4+
# Sub-task: Create subroutine 'get_date_from_filename'
5+
sub get_date_from_filename {
6+
my ($filename) = @_;
7+
$filename =~ /(\d{4}-\d{2}-\d{2})/;
8+
return $1;
9+
}
10+
11+
# Sub-task: Create subroutine 'slurp_file'
12+
sub slurp_file {
13+
my ($filename) = @_;
14+
local $/;
15+
open my $fh, '<', $filename or die "Could not open file '$filename': $!";
16+
my $contents = <$fh>;
17+
close $fh;
18+
return $contents;
19+
}
20+
21+
# Sub-task: Create subroutine 'contains_inactive_coauthors'
22+
sub contains_inactive_coauthors {
23+
my ($contents) = @_;
24+
return $contents =~ /#+\s*Inactive Co-Authors/i;
25+
}
26+
27+
# Sub-task: Create subroutine 'contains_active_coauthors'
28+
sub contains_active_coauthors {
29+
my ($contents) = @_;
30+
return $contents =~ /#+\s*Active Co-Authors/i;
31+
}
32+
33+
# Sub-task: Create subroutine 'contains_session_date'
34+
sub contains_session_date {
35+
my ($contents) = @_;
36+
return $contents =~ /#+\s*Session Date/i;
37+
}
38+
39+
# Sub-task: Create subroutine 'delete_inactive_coauthors'
40+
sub delete_inactive_coauthors {
41+
$_[0] =~ s/(#+\s*Inactive Co-Authors.*?)(?=#+\s*\w)/\n/si;
42+
}
43+
44+
# Sub-task: Create subroutine 'normalize_coauthor_heading'
45+
sub normalize_coauthor_heading {
46+
$_[0] =~ s/#+\s*.*?Co-Author.*/## Co-Authors/gi;
47+
}
48+
49+
# Sub-task: Create subroutine 'cleanup_file'
50+
sub cleanup_file {
51+
my ($filename) = @_;
52+
my $original_contents = slurp_file($filename);
53+
my $contents = $original_contents;
54+
my $date_as_string = get_date_from_filename($filename);
55+
56+
# Add session date if not present
57+
$contents = "## Session Date: $date_as_string\n\n$contents" unless contains_session_date($contents);
58+
59+
# Delete inactive coauthors if necessary
60+
delete_inactive_coauthors($contents) if contains_active_coauthors($contents) && contains_inactive_coauthors($contents);
61+
62+
# Normalize coauthor headings
63+
normalize_coauthor_heading($contents);
64+
65+
if ($contents eq $original_contents) {
66+
print "No changes were needed for $filename\n";
67+
} else {
68+
print "Changes were made to $filename\n";
69+
my ($mode, $atime, $mtime) = (stat $filename)[2, 8, 9];
70+
my $new_filename = $filename . '.new';
71+
open my $fh, '>', $new_filename or die "Could not open file '$new_filename': $!";
72+
print $fh $contents;
73+
close $fh;
74+
chmod $mode & 07777, $new_filename;
75+
utime $atime, $mtime, $new_filename;
76+
77+
# File manipulation
78+
rename $filename, $filename . '.original';
79+
rename $new_filename, $filename;
80+
81+
print "You can view changes by issuing this command:\n";
82+
print "diff -u " . $filename . ".original " . $filename . "\n";
83+
}
84+
}
85+
86+
# Sub-task: Create subroutine 'main'
87+
sub main {
88+
foreach my $filename (@ARGV) {
89+
cleanup_file($filename);
90+
}
91+
}
92+
93+
# Call main
94+
main() if @ARGV;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
Ignore previous instructions.
2+
3+
# Task: perform cleanup on files
4+
5+
## Input
6+
7+
The files have names like
8+
session-notes-2022-10-20.md
9+
session-notes-2022-11-03.md
10+
session-notes-2022-11-10.md
11+
session-notes-2022-11-24.md
12+
session-notes-2022-12-01.md
13+
14+
The files are in markdown format.
15+
16+
Specifically, 1st-level headers have 1 "#" at beginning of line and 2nd-level headers have "##"... likewise for 3rd-level
17+
18+
## Cleanup
19+
20+
All regular expresssion 'match' and 'substitute' operations should do case-insensitive matching.
21+
22+
Create code to accomplish each sub-task in Python
23+
24+
25+
### Sub-task: Create subroutine 'get_date_from_filename'
26+
- parameter: filename
27+
- return: date portion of the filename
28+
29+
### Sub-task: Create subroutine 'slurp_file'
30+
- parameter: filename
31+
- return: entire contents of file as a string
32+
33+
### Sub-task: Create subroutine 'contains_inactive_coauthors'
34+
- argument: contents
35+
- return: boolean. true iff 'contents' matches (case-insensitive) a 1st or 2nd level header with "Inactive Co-Authors"
36+
37+
### Sub-task: Create subroutine 'contains_active_coauthors'
38+
- argument: contents
39+
- return: boolean. true iff 'contents' matches (case-insensitive) a 1st or 2nd level header with "Active Co-Authors"
40+
41+
### Sub-task: Create subroutine 'contains_session_date'
42+
- argument: contents
43+
- return: boolean. true iff 'contents' matches (case-insensitive) a 1st or 2nd level header with "Session Date"
44+
45+
### Sub-task: Create subroutine: 'delete_inactive_coauthors'
46+
- argument: contents
47+
- action: if there is a 1st or 2nd level header that matches "Inactive Co-Authors", delete the whole section (i.e. the header through, but not including, the next header)
48+
- return: none. But assure that the argument has changes if they were made
49+
50+
### Sub-task: Create subroutine 'normalize_coauthor_heading'
51+
- argument: contents
52+
- action: Any header that contains "Co-Author", whether or not it contains other text, should be rewritten to be a 2nd-level header with only "Co-Authors"
53+
- return: none. But assure that the argument has changes if they were made
54+
55+
### Sub-task: Create subroutine 'cleanup_file'
56+
- argument: filename
57+
- actions
58+
1. slurp file contents into variable 'original_contents' and also 'contents'.
59+
2. set 'date_as_string' from 'filename'
60+
3. if 'contents' does not contain session date, add a 1st-level header to the beginning with "Session Date" followed by value of 'date_as_string'
61+
4. if 'contents' contains active coauthors AND 'contents' contains inactive coauthors, delete inactive coauthors
62+
5. if 'contents' and 'original_contents' are identical
63+
Notify user "No changes were needed"
64+
else
65+
a. Notify user that "Changes were made"
66+
b. create a new file to contain changed text
67+
- name based on oiginal name with .new appended
68+
- same mode as original file
69+
- same modification times as original file
70+
c. write 'contents' to the *.new file
71+
d. rename original file to have ".original" appended to filename
72+
e. rename file with new text (and .new appended) to original filename
73+
f. Notify user "You can view changes by issuing this command"...
74+
... then, on a new line, output command "diff -u original_backup_file new_file"
75+
Note: Surround file manipulation commands with ex
76+
77+
### Sub-task: Create subroutine 'main'
78+
- foreach filename given on the command line, pass the filename to "cleanup_file"
79+
80+
### Sub-task: Consolidate code
81+
- Display all sub-task code in python code block
82+
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Python code for the specified tasks
2+
3+
import re
4+
import os
5+
import shutil
6+
import sys
7+
8+
def get_date_from_filename(filename):
9+
match = re.search(r'(\d{4}-\d{2}-\d{2})', filename, re.IGNORECASE)
10+
return match.group(1) if match else None
11+
12+
def slurp_file(filename):
13+
try:
14+
with open(filename, 'r') as file:
15+
return file.read()
16+
except FileNotFoundError:
17+
return None
18+
19+
def contains_inactive_coauthors(contents):
20+
return bool(re.search(r'^#+\s*Inactive Co-Authors', contents, re.IGNORECASE | re.MULTILINE))
21+
22+
def contains_active_coauthors(contents):
23+
return bool(re.search(r'^#+\s*Active Co-Authors', contents, re.IGNORECASE | re.MULTILINE))
24+
25+
def contains_session_date(contents):
26+
return bool(re.search(r'^#+\s*Session Date', contents, re.IGNORECASE | re.MULTILINE))
27+
28+
def delete_inactive_coauthors(contents):
29+
return re.sub(r'^#+\s*Inactive Co-Authors.*?(?=^#|\Z)', '', contents, flags=re.IGNORECASE | re.MULTILINE | re.DOTALL)
30+
31+
def normalize_coauthor_heading(contents):
32+
return re.sub(r'^#+\s*.*Co-Author.*', '## Co-Authors', contents, flags=re.IGNORECASE | re.MULTILINE)
33+
34+
def cleanup_file(filename):
35+
original_contents = slurp_file(filename)
36+
if original_contents is None:
37+
print(f"File not found: {filename}")
38+
return
39+
40+
contents = original_contents
41+
date_as_string = get_date_from_filename(filename)
42+
43+
if not contains_session_date(contents):
44+
contents = f"# Session Date: {date_as_string}\n" + contents
45+
46+
if contains_active_coauthors(contents) and contains_inactive_coauthors(contents):
47+
contents = delete_inactive_coauthors(contents)
48+
49+
contents = normalize_coauthor_heading(contents)
50+
51+
if contents == original_contents:
52+
print(f"No changes were needed for the file: {filename}")
53+
else:
54+
print(f"Changes were made to the file: {filename}")
55+
new_filename = filename + ".new"
56+
with open(new_filename, 'w') as new_file:
57+
new_file.write(contents)
58+
shutil.copystat(filename, new_filename)
59+
original_backup_filename = filename + ".original"
60+
os.rename(filename, original_backup_filename)
61+
os.rename(new_filename, filename)
62+
print(f"You can view changes by issuing this command: diff -u {original_backup_filename} {filename}")
63+
64+
def main():
65+
for filename in sys.argv[1:]:
66+
cleanup_file(filename)
67+
68+
if __name__ == "__main__":
69+
main()

session-notes/cleanup-notes/doit

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /bin/bash
2+
3+
git_toplevel="$(git rev-parse --show-toplevel)"
4+
note_directory="${git_toplevel}/session-notes"
5+
script_directory="${note_directory}/cleanup-notes"
6+
script_path="${script_directory}/cleanup_session_notes.py"
7+
8+
cd "${note_directory}" || exit 2
9+
10+
11+
12+
for arg in "$@"
13+
do
14+
if [[ ! -f "$arg" ]]; then
15+
date="$arg"
16+
filename="session-notes-${date}.md"
17+
else
18+
filename="$arg"
19+
fi
20+
21+
. "${script_directory}/venv/bin/activate" || exit 3
22+
23+
python "${script_path}" "${filename}"
24+
done
25+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Updating this file for a new session
2+
3+
The point of this is to list all manual steps that we have to do in a session as a reminder, and get rid of them by automating them later.
4+
5+
Start of Session
6+
- If new participants, add them both to (1) daily file and (2) template file
7+
(While template is open, float active participants up in the list)
8+
9+
During Session
10+
As work proceeds
11+
- Update backlog and WIP
12+
- Copy Co-authors from here to commit message
13+
14+
Close of Session
15+
- Remove "Inactive Co-Authors" section completely (to prevent spurious github changes)
16+
- Remove this whole "Updating..." section, leaving "Session Date" at top of file
17+
- Add notes for retro
18+
- Add ideas for next time
19+
- Commit final change
20+
- confirm that the automation worked (cleanup script of session notes which should be a commit hook)
21+
- (Maybe) delete Gitpod.io work space

session-notes/session-notes-2022-10-13.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2022-10-13
12
# How did that feel?
23
- Liked the Game, is cool. Works well as a timer (has bugs). Like a mini retro all the time.
34
- Great Time

session-notes/session-notes-2022-10-20.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2022-10-20
12
# How did that feel?
23
- Nice +1
34
- Interesting

session-notes/session-notes-2022-11-03.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2022-11-03
12
# How did that feel?
23
- Enjoyed it, a bit of small talk in the beggining
34
- Felt productive, made good progress

session-notes/session-notes-2022-11-10.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2022-11-10
12
# How did that feel?
23
- I like working on Testinfrastructure
34
- Nice engineering challenge

session-notes/session-notes-2022-11-24.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2022-11-24
12
# How did that feel?
23
- frustrating +1
34
- happy that we found the cause in the end +1

session-notes/session-notes-2022-12-01.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2022-12-01
12
# How did that feel?
23
- Challenging +100
34
- Not Stable, constantly port in use

session-notes/session-notes-2022-12-08.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2022-12-08
12
# Goal
23

34
- Fix inconsistent test failures around the wsserver

session-notes/session-notes-2022-12-15.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2022-12-15
12
# Goal
23

34
- curios to test the rotation issue again manually

session-notes/session-notes-2022-12-22.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2022-12-22
12
# Goal
23

34
- [X] !! potential bug: rotate button should not use rotateToTarget

session-notes/session-notes-2023-01-05.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2023-01-05
12
# Goal
23

34
- [x] For next time we could take a look at this one:

session-notes/session-notes-2023-01-12.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2023-01-12
12
# Goal
23
- Bug: Game ID should be in the URL
34
- Exploratory testing

session-notes/session-notes-2023-01-19.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2023-01-19
12
# Goal
23
- Limit number of points to 3 per role
34
- Exploratory testing

session-notes/session-notes-2023-01-26.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2023-01-26
12
# Goal
23
- Exploratory testing
34
- A: which part? Q: all the app

session-notes/session-notes-2023-02-02.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2023-02-02
12
Co-Authored-By: Nitsan Avni <[email protected]>
23
Co-Authored-By: Eddie Bush <[email protected]>
34
Co-Authored-By: Michael R. Wolf <[email protected]>

session-notes/session-notes-2023-02-09.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2023-02-09
12
Co-Authored-By: Nitsan Avni <[email protected]>
23
Co-Authored-By: Eddie Bush <[email protected]>
34
Co-Authored-By: Rea <[email protected]>

session-notes/session-notes-2023-02-16.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2023-02-16
12
Co-Authored-By: Nitsan Avni <[email protected]>
23
Co-Authored-By: Michael R. Wolf <[email protected]>
34

session-notes/session-notes-2023-02-23.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2023-02-23
12
Co-Authored-By: Rea <[email protected]>
23
Co-Authored-By: Tsvetan Tsvetanov <[email protected]>
34
Co-Authored-By: Michael R. Wolf <[email protected]>

session-notes/session-notes-2023-03-02.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2023-03-02
12
Co-Authored-By: arrockt <[email protected]>
23
Co-Authored-By: Austin Chadwick <[email protected]>
34
Co-Authored-By: Blessed538 <[email protected]>

session-notes/session-notes-2023-03-09.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2023-03-09
12
Co-Authored-By: Gregor Riegler <[email protected]>
23
Co-Authored-By: Joel Silberman <[email protected]>
34
Co-Authored-By: Michael R. Wolf <[email protected]>

session-notes/session-notes-2023-03-16.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Session Date: 2023-03-16
12
Co-Authored-By: Eddie Bush <[email protected]>
23
Co-Authored-By: Joel Silberman <[email protected]>
34
Co-Authored-By: Nitsan Avni <[email protected]>

0 commit comments

Comments
 (0)