Skip to content
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

Automation Script: find_moved_or_renamed_commit #1559

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions auto-find-moved-or-renamed/find_moved_or_renamed_commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# This script identifies the commit where a specified function was modified,
# starting from a given commit, and handles cases where the function or file
# might have been renamed or moved.

# Usage:
# ./find_moved_or_renamed_commit.sh <FUNCTION_NAME> <FILENAME> <START_COMMIT>

# Parameters:
FUNCTION_NAME="$1"
FILENAME="$2" # Relative Path
START_COMMIT="$3"

if [ -z "$FUNCTION_NAME" ] || [ -z "$FILENAME" ] || [ -z "$START_COMMIT" ]; then
echo "Usage: $0 <FUNCTION_NAME> <FILENAME> <START_COMMIT>"
exit 1
fi

# Ensure we're in the root directory of the repository
cd "$(git rev-parse --show-toplevel)"

METHOD_REGEX="(public|protected|private|static|\s)+\s+.*\s+$FUNCTION_NAME\s*\(.*\)"

echo "Checking for function renames or file renames/moves..."

# Track file renames: See commits where the file was renamed.
# Track function changes: See commits where the function was modified, or removed.
git log "$START_COMMIT"..HEAD \
--follow \
--find-renames \
-G"$METHOD_REGEX" \
-p \
--name-status \
--reverse \
--color \
--decorate \
-- "$FILENAME" | less -R
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script is not automatically quit after showing the output. Maybe try -- "$FILENAME" | cat instead of less -R , or directly output the console to an outputfile

41 changes: 41 additions & 0 deletions auto-find-moved-or-renamed/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Overview
This automation script is designed to identify the specific commit that moved or renamed a test function or test file from the ones recorded in the IDOFT repository.

# Instructions
1. Copy and paste `find_moved_or_renamed_commit.sh` to the Repo you are working on.
2. `git checkout xxx` (replace xxx with the commit hash that the flake test was detected in IDOFT)
3. Find and copy the **Relative Path** of the given testing file, it should contain the given FUNCTION_NAME. (Paste it somewhere, this is the FILENAME that will be used later)
4. `git checkout master` (or whichever branch you want that has the latest commit)
5. Execute the script by running:

``` bash
chmod +x find_moved_or_renamed_commit.sh`
./find_moved_or_renamed_commit.sh <FUNCTION_NAME> <FILENAME> <START_COMMIT>
```

## Examples

### A Row in IDOFT
```
https://github.com/apache/ignite-3,a1aa7fd4e2398c72827777ec5417d67915ff4da3,modules/configuration,org.apache.ignite.internal.configuration.asm.ConfigurationAsmGeneratorTest.testConstructInternalConfig,ID,MovedOrRenamed,,https://github.com/apache/ignite-3/commit/b48ddcba7cd2bd3b9a053ae131c25b44a0400e27
```

### Execute
```
./find_moved_or_renamed_commit.sh testConstructInternalConfig modules/configuration/src/test/java/org/apache/ignite/internal/configuration/asm/ConfigurationAsmGeneratorTest.java a1aa7fd4e2398c72827777ec5417d67915ff4da3
```

### Output
```
commit b48ddcba7cd2bd3b9a053ae131c25b44a0400e27
Author: Aleksandr Pakhomov <[email protected]>
Date: Wed Apr 26 20:02:34 2023 +0400

IGNITE-19152 Use schema information in LocalFileConfigurationStorage (#1988)

---------

Co-authored-by: Ivan Bessonov <[email protected]>

D modules/configuration/src/test/java/org/apache/ignite/internal/configuration/asm/ConfigurationAsmGeneratorTest.java
```
Loading