-
Notifications
You must be signed in to change notification settings - Fork 4
session-note cleanup (via ChatGPT generated code) #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
4429283
7559b12
2aebef8
77e35ab
267273f
03d63d0
2e8cd58
2d077a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
43 ## Co-Authors | ||
34 Co-Authored-By: Nitsan Avni <[email protected]> | ||
34 Co-Authored-By: Michael R. Wolf <[email protected]> | ||
30 Co-Authored-By: Joel Silberman <[email protected]> | ||
27 Co-Authored-By: Gregor Riegler <[email protected]> | ||
15 Co-Authored-By: 4dsherwood <[email protected]> | ||
9 Co-Authored-By: Eddie Bush <[email protected]> | ||
8 Co-Authored-By: Rea <[email protected]> | ||
6 Co-Authored-By: Tsvetan Tsvetanov <[email protected]> | ||
5 Co-Authored-By: Idan Melamed <[email protected]> | ||
5 Co-Authored-By: Blaise Pabon <[email protected]> | ||
4 Co-Authored-By: Nathaniel Herman <[email protected]> | ||
3 Co-Authored-By: arrockt <[email protected]> | ||
3 Co-Authored-By: Willem Larsen <[email protected]> | ||
3 Co-Authored-By: Gabriel Mbaiorga <[email protected]> | ||
3 Co-Authored-By: Blessed538 <[email protected]> | ||
3 Co-Authored-By: Austin Chadwick <[email protected]> | ||
2 Co-Authored-By: David Campey <[email protected]> | ||
2 - Remind newcomers to enter their author info (eg. Co-Authored-By: Blaise Pabon <[email protected]>) | ||
1 Co-Authored-by: Zac Ball <[email protected]> | ||
1 Co-Authored-By: new participant | ||
1 Co-Authored-By: Woody Zuill <[email protected]> | ||
1 Co-Authored-By: Nathaniel ... | ||
1 Co-Authored-By: Llewellyn Falco <[email protected]> | ||
1 Co-Authored-By: Kitastro <[email protected]> | ||
1 Co-Authored-By: Ethan Strominger <[email protected]> | ||
1 Co-Authored-By: Emily Bache <[email protected]> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
43 Co-Authored-By: Michael R. Wolf <[email protected]> | ||
38 Co-Authored-By: Nitsan Avni <[email protected]> | ||
37 Co-Authored-By: Joel Silberman <[email protected]> | ||
34 Co-Authored-By: Gregor Riegler <[email protected]> | ||
32 Co-Authored-By: Rea <[email protected]> | ||
31 Co-Authored-By: Eddie Bush <[email protected]> | ||
29 Co-Authored-By: Tsvetan Tsvetanov <[email protected]> | ||
29 ## Active Co-Authors | ||
27 Co-Authored-By: arrockt <[email protected]> | ||
27 Co-Authored-By: Willem Larsen <[email protected]> | ||
27 Co-Authored-By: Idan Melamed <[email protected]> | ||
27 Co-Authored-By: Gabriel Mbaiorga <[email protected]> | ||
27 Co-Authored-By: Blessed538 <[email protected]> | ||
27 Co-Authored-By: Austin Chadwick <[email protected]> | ||
24 Co-Authored-By: 4dsherwood <[email protected]> | ||
24 ## Inactive Co-Authors | ||
21 Co-Authored-By: David Campey <[email protected]> | ||
20 Co-Authored-by: Zac Ball <[email protected]> | ||
14 Co-Authored-By: Kitastro <[email protected]> | ||
12 # Co-Authors (This Session) | ||
9 Co-Authored-By: Blaise Pabon <[email protected]> | ||
8 Co-Authored-By: Woody Zuill <[email protected]> | ||
6 Co-Authored-By: Llewellyn Falco <[email protected]> | ||
5 Co-Authored-By: Nathaniel Herman <[email protected]> | ||
2 - Remind newcomers to enter their author info (eg. Co-Authored-By: Blaise Pabon <[email protected]>) | ||
1 Lastly, the deliberate effort to get to know each other better reveals an understanding of the importance of team dynamics and the value of human connection in a productive work environment.# Co-Authors (This Session) | ||
1 Co-Authored-By: new participant | ||
1 Co-Authored-By: Nathaniel ... | ||
1 Co-Authored-By: Ethan Strominger <[email protected]> | ||
1 Co-Authored-By: Emily Bache <[email protected]> | ||
1 - Intention needs to be documented right there, when it happensCo-Authored-By: Nitsan Avni <[email protected]> | ||
1 - Nitsans Taste: One Terminal at a time# Co-Authors (This Session) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
use strict; | ||
use warnings; | ||
|
||
# Sub-task: Create subroutine 'get_date_from_filename' | ||
sub get_date_from_filename { | ||
my ($filename) = @_; | ||
$filename =~ /(\d{4}-\d{2}-\d{2})/; | ||
return $1; | ||
} | ||
|
||
# Sub-task: Create subroutine 'slurp_file' | ||
sub slurp_file { | ||
my ($filename) = @_; | ||
local $/; | ||
open my $fh, '<', $filename or die "Could not open file '$filename': $!"; | ||
my $contents = <$fh>; | ||
close $fh; | ||
return $contents; | ||
} | ||
|
||
# Sub-task: Create subroutine 'contains_inactive_coauthors' | ||
sub contains_inactive_coauthors { | ||
my ($contents) = @_; | ||
return $contents =~ /#+\s*Inactive Co-Authors/i; | ||
} | ||
|
||
# Sub-task: Create subroutine 'contains_active_coauthors' | ||
sub contains_active_coauthors { | ||
my ($contents) = @_; | ||
return $contents =~ /#+\s*Active Co-Authors/i; | ||
} | ||
|
||
# Sub-task: Create subroutine 'contains_session_date' | ||
sub contains_session_date { | ||
my ($contents) = @_; | ||
return $contents =~ /#+\s*Session Date/i; | ||
} | ||
|
||
# Sub-task: Create subroutine 'delete_inactive_coauthors' | ||
sub delete_inactive_coauthors { | ||
$_[0] =~ s/(#+\s*Inactive Co-Authors.*?)(?=#+\s*\w)/\n/si; | ||
} | ||
|
||
# Sub-task: Create subroutine 'normalize_coauthor_heading' | ||
sub normalize_coauthor_heading { | ||
$_[0] =~ s/#+\s*.*?Co-Author.*/## Co-Authors/gi; | ||
} | ||
|
||
# Sub-task: Create subroutine 'cleanup_file' | ||
sub cleanup_file { | ||
my ($filename) = @_; | ||
my $original_contents = slurp_file($filename); | ||
my $contents = $original_contents; | ||
my $date_as_string = get_date_from_filename($filename); | ||
|
||
# Add session date if not present | ||
$contents = "## Session Date: $date_as_string\n\n$contents" unless contains_session_date($contents); | ||
|
||
# Delete inactive coauthors if necessary | ||
delete_inactive_coauthors($contents) if contains_active_coauthors($contents) && contains_inactive_coauthors($contents); | ||
|
||
# Normalize coauthor headings | ||
normalize_coauthor_heading($contents); | ||
|
||
if ($contents eq $original_contents) { | ||
print "No changes were needed for $filename\n"; | ||
} else { | ||
print "Changes were made to $filename\n"; | ||
my ($mode, $atime, $mtime) = (stat $filename)[2, 8, 9]; | ||
my $new_filename = $filename . '.new'; | ||
open my $fh, '>', $new_filename or die "Could not open file '$new_filename': $!"; | ||
print $fh $contents; | ||
close $fh; | ||
chmod $mode & 07777, $new_filename; | ||
utime $atime, $mtime, $new_filename; | ||
|
||
# File manipulation | ||
rename $filename, $filename . '.original'; | ||
rename $new_filename, $filename; | ||
|
||
print "You can view changes by issuing this command:\n"; | ||
print "diff -u " . $filename . ".original " . $filename . "\n"; | ||
} | ||
} | ||
|
||
# Sub-task: Create subroutine 'main' | ||
sub main { | ||
foreach my $filename (@ARGV) { | ||
cleanup_file($filename); | ||
} | ||
} | ||
|
||
# Call main | ||
main() if @ARGV; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,82 @@ | ||||||
Ignore previous instructions. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? |
||||||
|
||||||
# Task: perform cleanup on files | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
## Input | ||||||
|
||||||
The files have names like | ||||||
session-notes-2022-10-20.md | ||||||
session-notes-2022-11-03.md | ||||||
session-notes-2022-11-10.md | ||||||
session-notes-2022-11-24.md | ||||||
session-notes-2022-12-01.md | ||||||
|
||||||
The files are in markdown format. | ||||||
|
||||||
Specifically, 1st-level headers have 1 "#" at beginning of line and 2nd-level headers have "##"... likewise for 3rd-level | ||||||
|
||||||
## Cleanup | ||||||
|
||||||
All regular expresssion 'match' and 'substitute' operations should do case-insensitive matching. | ||||||
|
||||||
Create code to accomplish each sub-task in Python | ||||||
|
||||||
|
||||||
### Sub-task: Create subroutine 'get_date_from_filename' | ||||||
- parameter: filename | ||||||
- return: date portion of the filename | ||||||
|
||||||
### Sub-task: Create subroutine 'slurp_file' | ||||||
- parameter: filename | ||||||
- return: entire contents of file as a string | ||||||
|
||||||
### Sub-task: Create subroutine 'contains_inactive_coauthors' | ||||||
- argument: contents | ||||||
- return: boolean. true iff 'contents' matches (case-insensitive) a 1st or 2nd level header with "Inactive Co-Authors" | ||||||
|
||||||
### Sub-task: Create subroutine 'contains_active_coauthors' | ||||||
- argument: contents | ||||||
- return: boolean. true iff 'contents' matches (case-insensitive) a 1st or 2nd level header with "Active Co-Authors" | ||||||
|
||||||
### Sub-task: Create subroutine 'contains_session_date' | ||||||
- argument: contents | ||||||
- return: boolean. true iff 'contents' matches (case-insensitive) a 1st or 2nd level header with "Session Date" | ||||||
|
||||||
### Sub-task: Create subroutine: 'delete_inactive_coauthors' | ||||||
- argument: contents | ||||||
- 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) | ||||||
- return: none. But assure that the argument has changes if they were made | ||||||
|
||||||
### Sub-task: Create subroutine 'normalize_coauthor_heading' | ||||||
- argument: contents | ||||||
- 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" | ||||||
- return: none. But assure that the argument has changes if they were made | ||||||
|
||||||
### Sub-task: Create subroutine 'cleanup_file' | ||||||
- argument: filename | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. English as a programming language 👏 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact, can we get the script generation to be so reliable that we don't need to commit the artifact, only the prompt? Similar to the way we treat compiled / transpiled artifacts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the way you're thinking. Let's explore it. |
||||||
- actions | ||||||
1. slurp file contents into variable 'original_contents' and also 'contents'. | ||||||
2. set 'date_as_string' from 'filename' | ||||||
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' | ||||||
4. if 'contents' contains active coauthors AND 'contents' contains inactive coauthors, delete inactive coauthors | ||||||
5. if 'contents' and 'original_contents' are identical | ||||||
Notify user "No changes were needed" | ||||||
else | ||||||
a. Notify user that "Changes were made" | ||||||
b. create a new file to contain changed text | ||||||
- name based on oiginal name with .new appended | ||||||
- same mode as original file | ||||||
- same modification times as original file | ||||||
c. write 'contents' to the *.new file | ||||||
d. rename original file to have ".original" appended to filename | ||||||
e. rename file with new text (and .new appended) to original filename | ||||||
f. Notify user "You can view changes by issuing this command"... | ||||||
... then, on a new line, output command "diff -u original_backup_file new_file" | ||||||
Note: Surround file manipulation commands with ex | ||||||
|
||||||
### Sub-task: Create subroutine 'main' | ||||||
- foreach filename given on the command line, pass the filename to "cleanup_file" | ||||||
|
||||||
### Sub-task: Consolidate code | ||||||
- Display all sub-task code in python code block | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Python code for the specified tasks | ||
|
||
import re | ||
import os | ||
import shutil | ||
import sys | ||
|
||
def get_date_from_filename(filename): | ||
match = re.search(r'(\d{4}-\d{2}-\d{2})', filename, re.IGNORECASE) | ||
return match.group(1) if match else None | ||
|
||
def slurp_file(filename): | ||
try: | ||
with open(filename, 'r') as file: | ||
return file.read() | ||
except FileNotFoundError: | ||
return None | ||
|
||
def contains_inactive_coauthors(contents): | ||
return bool(re.search(r'^#+\s*Inactive Co-Authors', contents, re.IGNORECASE | re.MULTILINE)) | ||
|
||
def contains_active_coauthors(contents): | ||
return bool(re.search(r'^#+\s*Active Co-Authors', contents, re.IGNORECASE | re.MULTILINE)) | ||
|
||
def contains_session_date(contents): | ||
return bool(re.search(r'^#+\s*Session Date', contents, re.IGNORECASE | re.MULTILINE)) | ||
|
||
def delete_inactive_coauthors(contents): | ||
return re.sub(r'^#+\s*Inactive Co-Authors.*?(?=^#|\Z)', '', contents, flags=re.IGNORECASE | re.MULTILINE | re.DOTALL) | ||
|
||
def normalize_coauthor_heading(contents): | ||
return re.sub(r'^#+\s*.*Co-Author.*', '## Co-Authors', contents, flags=re.IGNORECASE | re.MULTILINE) | ||
|
||
def cleanup_file(filename): | ||
original_contents = slurp_file(filename) | ||
if original_contents is None: | ||
print(f"File not found: {filename}") | ||
return | ||
|
||
contents = original_contents | ||
date_as_string = get_date_from_filename(filename) | ||
|
||
if not contains_session_date(contents): | ||
contents = f"# Session Date: {date_as_string}\n" + contents | ||
|
||
if contains_active_coauthors(contents) and contains_inactive_coauthors(contents): | ||
contents = delete_inactive_coauthors(contents) | ||
|
||
contents = normalize_coauthor_heading(contents) | ||
|
||
if contents == original_contents: | ||
print(f"No changes were needed for the file: {filename}") | ||
else: | ||
print(f"Changes were made to the file: {filename}") | ||
new_filename = filename + ".new" | ||
with open(new_filename, 'w') as new_file: | ||
new_file.write(contents) | ||
shutil.copystat(filename, new_filename) | ||
original_backup_filename = filename + ".original" | ||
os.rename(filename, original_backup_filename) | ||
os.rename(new_filename, filename) | ||
print(f"You can view changes by issuing this command: diff -u {original_backup_filename} {filename}") | ||
|
||
def main(): | ||
for filename in sys.argv[1:]: | ||
cleanup_file(filename) | ||
|
||
if __name__ == "__main__": | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#! /bin/bash | ||
|
||
git_toplevel="$(git rev-parse --show-toplevel)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Learn something new every day |
||
note_directory="${git_toplevel}/session-notes" | ||
script_directory="${note_directory}/cleanup-notes" | ||
script_path="${script_directory}/cleanup_session_notes.py" | ||
|
||
cd "${note_directory}" || exit 2 | ||
|
||
|
||
|
||
for arg in "$@" | ||
do | ||
if [[ ! -f "$arg" ]]; then | ||
date="$arg" | ||
filename="session-notes-${date}.md" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could've done this inside the perl/python script |
||
else | ||
filename="$arg" | ||
fi | ||
|
||
. "${script_directory}/venv/bin/activate" || exit 3 | ||
|
||
python "${script_path}" "${filename}" | ||
done | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Session Date: 2022-10-13 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🏵️ |
||
# How did that feel? | ||
- Liked the Game, is cool. Works well as a timer (has bugs). Like a mini retro all the time. | ||
- Great Time | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Session Date: 2022-10-20 | ||
# How did that feel? | ||
- Nice +1 | ||
- Interesting | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Session Date: 2022-11-24 | ||
# How did that feel? | ||
- frustrating +1 | ||
- happy that we found the cause in the end +1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Session Date: 2022-12-01 | ||
# How did that feel? | ||
- Challenging +100 | ||
- Not Stable, constantly port in use | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Session Date: 2022-12-08 | ||
# Goal | ||
|
||
- Fix inconsistent test failures around the wsserver | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Session Date: 2022-12-15 | ||
# Goal | ||
|
||
- curios to test the rotation issue again manually | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Session Date: 2022-12-22 | ||
# Goal | ||
|
||
- [X] !! potential bug: rotate button should not use rotateToTarget | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Session Date: 2023-01-05 | ||
# Goal | ||
|
||
- [x] For next time we could take a look at this one: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Session Date: 2023-01-12 | ||
# Goal | ||
- Bug: Game ID should be in the URL | ||
- Exploratory testing | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Session Date: 2023-01-19 | ||
# Goal | ||
- Limit number of points to 3 per role | ||
- Exploratory testing | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are those files necessary?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, but I wanted some way to capture some results.
Suggestions for a better place to archive the quick-and-dirty data?