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

[PM-102559] Fix fdroid workflow failure #49

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 17 additions & 0 deletions metascoop/apps/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ func ReadIndex(path string) (index *RepoIndex, err error) {
return
}

// HasSignificantChanges compares two RepoIndex structs and determines if there are significant changes between them.
//
// Parameters:
// - old: A pointer to the original RepoIndex struct.
// - new: A pointer to the updated RepoIndex struct.
//
// Returns:
// - changedPath: A string representing the JSON path where a significant change was found.
// - changed: A boolean indicating whether a significant change was detected (true) or not (false).
//
// The function uses the diff package to compare the two structs. It ignores certain changes that are considered
// non-significant, such as updates to the "added" or "lastUpdated" timestamps of apps, and updates to the repo timestamp.
// Any other changes are considered significant.
//
// If a significant change is found, the function returns the path to the change and true.
// If no significant changes are found, it returns an empty string and false.

func HasSignificantChanges(old, new *RepoIndex) (changedPath string, changed bool) {
changelog, err := diff.Diff(old, new)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion metascoop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,11 @@ func main() {
cpath, haveSignificantChanges := apps.HasSignificantChanges(initialFdroidIndex, fdroidIndex)
if haveSignificantChanges {
log.Printf("The index %q had a significant change at JSON path %q", fdroidIndexFilePath, cpath)
// If there were no new commits, we add a commit title indicating index has changes.
if !hasNewCommits {
commitMsg.WriteString("Automatic index update\n\n")
}
commitMsg.WriteString("Index updated to reflect recent changes to the F-Droid repository.\n")
} else {
log.Printf("The index files didn't change significantly")

Expand All @@ -523,7 +528,7 @@ func main() {
// If there were modified files, we add them to the commit message
if len(modifiedFiles) > 0 {

// If there were no new commits, we add a commit title indicating only metadata changes.
// If there were no new commits, we add a commit title indicating only metadata changes occurred.
if !hasNewCommits {
commitMsg.WriteString("Automatic metadata updates\n\n")
}
Expand Down
2 changes: 2 additions & 0 deletions update_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ if [ -f "$COMMIT_MSG_FILE" ]; then

# Read the first line as the PR title
PR_TITLE=$(head -n 1 "$COMMIT_MSG_FILE")
echo "PR Title: $PR_TITLE"

# Read the remaining lines as the PR body
PR_BODY=$(tail -n +2 "$COMMIT_MSG_FILE")
echo "PR Body: $PR_BODY"

echo "Pushing changes..."
git add .
Expand Down