From 335fdc0624dd4811096ec23ba5fada36fff9ad5b Mon Sep 17 00:00:00 2001 From: limiting-factor Date: Thu, 28 May 2026 15:15:45 +0200 Subject: [PATCH] s/convertForgejo(.*)ToF3Path/getF3PathOf$1/ --- services/f3/driver/uuid_attachment.go | 4 +- services/f3/util/path.go | 112 +++++++++++++------------- services/f3/util/path_test.go | 4 +- 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/services/f3/driver/uuid_attachment.go b/services/f3/driver/uuid_attachment.go index cba001dc74..281b907cd2 100644 --- a/services/f3/driver/uuid_attachment.go +++ b/services/f3/driver/uuid_attachment.go @@ -39,9 +39,9 @@ func (o converterUUIDAndAttachment) UUIDToAttachment(ctx context.Context, uuid s panic(fmt.Errorf("GetAttachmentByUUID(%s): %w", uuid, err)) } - f3Path, err := f3_util.ConvertForgejoToF3Path(ctx, attachment) + f3Path, err := f3_util.GetF3PathOfResource(ctx, attachment) if err != nil { - panic(fmt.Errorf("ConvertForgejoToF3Path(%+v): %w", attachment, err)) + panic(fmt.Errorf("GetF3PathOfResource(%+v): %w", attachment, err)) } return f3Path, true diff --git a/services/f3/util/path.go b/services/f3/util/path.go index 9179391c3d..65f4c47ffb 100644 --- a/services/f3/util/path.go +++ b/services/f3/util/path.go @@ -31,20 +31,20 @@ func getF3PathOfRepository(ctx context.Context, repository *repo.Repository) (st return f3_tree.NewProjectPathString(ownerPath, repository.Owner.Name, repository.Name), nil } -func convertForgejoPullRequestToF3Path(ctx context.Context, pullRequest *issues.PullRequest) (string, error) { +func getF3PathOfPullRequest(ctx context.Context, pullRequest *issues.PullRequest) (string, error) { if err := pullRequest.LoadIssue(ctx); err != nil { - return "", fmt.Errorf("convertForgejoPullRequestToF3Path LoadIssue: %w", err) + return "", fmt.Errorf("getF3PathOfPullRequest LoadIssue: %w", err) } - return convertForgejoIssueToF3Path(ctx, true, pullRequest.Issue) + return getF3PathOfIssue(ctx, true, pullRequest.Issue) } -func convertForgejoIssueToF3Path(ctx context.Context, isPull bool, issue *issues.Issue) (string, error) { +func getF3PathOfIssue(ctx context.Context, isPull bool, issue *issues.Issue) (string, error) { if err := issue.LoadRepo(ctx); err != nil { - return "", fmt.Errorf("convertForgejoIssueToF3Path LoadRepo: %w", err) + return "", fmt.Errorf("getF3PathOfIssue LoadRepo: %w", err) } projectPath, err := getF3PathOfRepository(ctx, issue.Repo) if err != nil { - return "", fmt.Errorf("convertForgejoIssueToF3Path getF3PathOfRepository: %w", err) + return "", fmt.Errorf("getF3PathOfIssue getF3PathOfRepository: %w", err) } var issuePath string if isPull { @@ -55,13 +55,13 @@ func convertForgejoIssueToF3Path(ctx context.Context, isPull bool, issue *issues return issuePath, nil } -func convertForgejoCommentToF3Path(ctx context.Context, comment *issues.Comment) (string, error) { +func getF3PathOfComment(ctx context.Context, comment *issues.Comment) (string, error) { if err := comment.LoadIssue(ctx); err != nil { - return "", fmt.Errorf("convertForgejoCommentToF3Path LoadIssue: %w", err) + return "", fmt.Errorf("getF3PathOfComment LoadIssue: %w", err) } - commentablePath, err := convertForgejoIssueToF3Path(ctx, comment.Issue.IsPull, comment.Issue) + commentablePath, err := getF3PathOfIssue(ctx, comment.Issue.IsPull, comment.Issue) if err != nil { - return "", fmt.Errorf("convertForgejoCommentToF3Path convertForgejoIssueToF3Path: %w", err) + return "", fmt.Errorf("getF3PathOfComment getF3PathOfIssue: %w", err) } switch comment.Type { @@ -70,64 +70,64 @@ func convertForgejoCommentToF3Path(ctx context.Context, comment *issues.Comment) case issues.CommentTypeReview, issues.CommentTypeCode: review, err := issues.GetReviewByID(ctx, comment.ReviewID) if err != nil { - return "", fmt.Errorf("convertForgejoCommentToF3Path GetReviewByID: %w", err) + return "", fmt.Errorf("getF3PathOfComment GetReviewByID: %w", err) } - reviewPath, err := convertForgejoReviewToF3Path(ctx, review) + reviewPath, err := getF3PathOfReview(ctx, review) if err != nil { return "", err } return f3_tree.NewReviewCommentPathString(reviewPath, f3_util.ToString(comment.ID)), nil default: - err := fmt.Errorf("convertForgejoCommentToF3Path unexpected comment type %v", comment.Type) + err := fmt.Errorf("getF3PathOfComment unexpected comment type %v", comment.Type) log.Error(err.Error()) return "", err } } -func convertForgejoReleaseToF3Path(ctx context.Context, release *repo.Release) (string, error) { +func getF3PathOfRelease(ctx context.Context, release *repo.Release) (string, error) { if err := release.LoadRepo(ctx); err != nil { - return "", fmt.Errorf("convertForgejoReleaseToF3Path LoadRepo: %w", err) + return "", fmt.Errorf("getF3PathOfRelease LoadRepo: %w", err) } projectPath, err := getF3PathOfRepository(ctx, release.Repo) if err != nil { - return "", fmt.Errorf("convertForgejoReleaseToF3Path getF3PathOfRepository: %w", err) + return "", fmt.Errorf("getF3PathOfRelease getF3PathOfRepository: %w", err) } return f3_tree.NewReleasePathString(projectPath, f3_util.ToString(release.ID)), nil } -func convertForgejoAttachmentToF3Path(ctx context.Context, attachment *repo.Attachment) (string, error) { +func getF3PathOfAttachment(ctx context.Context, attachment *repo.Attachment) (string, error) { var attachablePath string if attachment.IssueID != 0 { if attachment.CommentID != 0 { comment, err := issues.GetCommentByID(ctx, attachment.CommentID) if err != nil { - return "", fmt.Errorf("convertForgejoAttachmentToF3Path GetCommentByID: %w", err) + return "", fmt.Errorf("getF3PathOfAttachment GetCommentByID: %w", err) } - attachablePath, err = convertForgejoCommentToF3Path(ctx, comment) + attachablePath, err = getF3PathOfComment(ctx, comment) if err != nil { - return "", fmt.Errorf("convertForgejoAttachmentToF3Path convertForgejoCommentToF3Path: %w", err) + return "", fmt.Errorf("getF3PathOfAttachment getF3PathOfComment: %w", err) } } else { issue, err := issues.GetIssueByID(ctx, attachment.IssueID) if err != nil { - return "", fmt.Errorf("convertForgejoAttachmentToF3Path GetIssueByID: %w", err) + return "", fmt.Errorf("getF3PathOfAttachment GetIssueByID: %w", err) } - attachablePath, err = convertForgejoIssueToF3Path(ctx, issue.IsPull, issue) + attachablePath, err = getF3PathOfIssue(ctx, issue.IsPull, issue) if err != nil { - return "", fmt.Errorf("convertForgejoAttachmentToF3Path convertForgejoIssueToF3Path: %w", err) + return "", fmt.Errorf("getF3PathOfAttachment getF3PathOfIssue: %w", err) } } } else if attachment.ReleaseID != 0 { release, err := repo.GetReleaseByID(ctx, attachment.ReleaseID) if err != nil { - return "", fmt.Errorf("convertForgejoAttachmentToF3Path GetReleaseByID: %w", err) + return "", fmt.Errorf("getF3PathOfAttachment GetReleaseByID: %w", err) } - attachablePath, err = convertForgejoReleaseToF3Path(ctx, release) + attachablePath, err = getF3PathOfRelease(ctx, release) if err != nil { - return "", fmt.Errorf("convertForgejoAttachmentToF3Path convertForgejoReleaseToF3Path: %w", err) + return "", fmt.Errorf("getF3PathOfAttachment getF3PathOfRelease: %w", err) } } else { - err := fmt.Errorf("convertForgejoAttachmentToF3Path unexpected attachment with IssueID == 0 and ReleaseID == 0 %+v", attachment) + err := fmt.Errorf("getF3PathOfAttachment unexpected attachment with IssueID == 0 and ReleaseID == 0 %+v", attachment) log.Error(err.Error()) return "", err } @@ -135,71 +135,71 @@ func convertForgejoAttachmentToF3Path(ctx context.Context, attachment *repo.Atta return f3_tree.NewAttachmentPathString(attachablePath, f3_util.ToString(attachment.ID)), nil } -func convertForgejoReactionToF3Path(ctx context.Context, reaction *issues.Reaction) (string, error) { +func getF3PathOfReaction(ctx context.Context, reaction *issues.Reaction) (string, error) { var reactionablePath string if reaction.CommentID != 0 { comment, err := issues.GetCommentByID(ctx, reaction.CommentID) if err != nil { - return "", fmt.Errorf("convertForgejoReactionToF3Path GetCommentByID: %w", err) + return "", fmt.Errorf("getF3PathOfReaction GetCommentByID: %w", err) } - reactionablePath, err = convertForgejoCommentToF3Path(ctx, comment) + reactionablePath, err = getF3PathOfComment(ctx, comment) if err != nil { - return "", fmt.Errorf("convertForgejoReactionToF3Path convertForgejoCommentToF3Path: %w", err) + return "", fmt.Errorf("getF3PathOfReaction getF3PathOfComment: %w", err) } } else { issue, err := issues.GetIssueByID(ctx, reaction.IssueID) if err != nil { - return "", fmt.Errorf("convertForgejoReactionToF3Path GetIssueByID: %w", err) + return "", fmt.Errorf("getF3PathOfReaction GetIssueByID: %w", err) } - reactionablePath, err = convertForgejoIssueToF3Path(ctx, issue.IsPull, issue) + reactionablePath, err = getF3PathOfIssue(ctx, issue.IsPull, issue) if err != nil { - return "", fmt.Errorf("convertForgejoReactionToF3Path convertForgejoIssueToF3Path: %w", err) + return "", fmt.Errorf("getF3PathOfReaction getF3PathOfIssue: %w", err) } } return f3_tree.NewReactionPathString(reactionablePath, f3_util.ToString(reaction.ID)), nil } -func convertForgejoLabelToF3Path(ctx context.Context, label *issues.Label) (string, error) { +func getF3PathOfLabel(ctx context.Context, label *issues.Label) (string, error) { repository, err := repo.GetRepositoryByID(ctx, label.RepoID) if err != nil { - return "", fmt.Errorf("convertForgejoLabelToF3Path GetRepositoryByID: %w", err) + return "", fmt.Errorf("getF3PathOfLabel GetRepositoryByID: %w", err) } projectPath, err := getF3PathOfRepository(ctx, repository) if err != nil { - return "", fmt.Errorf("convertForgejoLabelToF3Path getF3PathOfRepository: %w", err) + return "", fmt.Errorf("getF3PathOfLabel getF3PathOfRepository: %w", err) } return f3_tree.NewLabelPathString(projectPath, f3_util.ToString(label.ID)), nil } -func convertForgejoMilestoneToF3Path(ctx context.Context, milestone *issues.Milestone) (string, error) { +func getF3PathOfMilestone(ctx context.Context, milestone *issues.Milestone) (string, error) { repository, err := repo.GetRepositoryByID(ctx, milestone.RepoID) if err != nil { - return "", fmt.Errorf("convertForgejoMilestoneToF3Path GetRepositoryByID: %w", err) + return "", fmt.Errorf("getF3PathOfMilestone GetRepositoryByID: %w", err) } projectPath, err := getF3PathOfRepository(ctx, repository) if err != nil { - return "", fmt.Errorf("convertForgejoMilestoneToF3Path getF3PathOfRepository: %w", err) + return "", fmt.Errorf("getF3PathOfMilestone getF3PathOfRepository: %w", err) } return f3_tree.NewMilestonePathString(projectPath, f3_util.ToString(milestone.ID)), nil } -func convertForgejoReviewToF3Path(ctx context.Context, review *issues.Review) (string, error) { +func getF3PathOfReview(ctx context.Context, review *issues.Review) (string, error) { issue, err := issues.GetIssueByID(ctx, review.IssueID) if err != nil { - return "", fmt.Errorf("convertForgejoReviewToF3Path GetIssueByID: %w", err) + return "", fmt.Errorf("getF3PathOfReview GetIssueByID: %w", err) } if !issue.IsPull { - return "", fmt.Errorf("convertForgejoReviewToF3Path the issue %d of review %d must be a pull request", review.ID, issue.ID) + return "", fmt.Errorf("getF3PathOfReview the issue %d of review %d must be a pull request", review.ID, issue.ID) } - pullRequestPath, err := convertForgejoIssueToF3Path(ctx, issue.IsPull, issue) + pullRequestPath, err := getF3PathOfIssue(ctx, issue.IsPull, issue) if err != nil { - return "", fmt.Errorf("convertForgejoReviewToF3Path convertForgejoIssueToF3Path: %w", err) + return "", fmt.Errorf("getF3PathOfReview getF3PathOfIssue: %w", err) } return f3_tree.NewReviewPathString(pullRequestPath, f3_util.ToString(review.ID)), nil } -func ConvertForgejoToF3Path(ctx context.Context, some any) (string, error) { +func GetF3PathOfResource(ctx context.Context, some any) (string, error) { switch o := some.(type) { case *repo.Repository: return getF3PathOfRepository(ctx, o) @@ -210,25 +210,25 @@ func ConvertForgejoToF3Path(ctx context.Context, some any) (string, error) { case *repo.Topic: return f3_tree.NewTopicPathString(f3_util.ToString(o.ID)), nil case *issues.Issue: - return convertForgejoIssueToF3Path(ctx, false, o) + return getF3PathOfIssue(ctx, false, o) case *issues.PullRequest: - return convertForgejoPullRequestToF3Path(ctx, o) + return getF3PathOfPullRequest(ctx, o) case *issues.Comment: - return convertForgejoCommentToF3Path(ctx, o) + return getF3PathOfComment(ctx, o) case *repo.Release: - return convertForgejoReleaseToF3Path(ctx, o) + return getF3PathOfRelease(ctx, o) case *repo.Attachment: - return convertForgejoAttachmentToF3Path(ctx, o) + return getF3PathOfAttachment(ctx, o) case *issues.Reaction: - return convertForgejoReactionToF3Path(ctx, o) + return getF3PathOfReaction(ctx, o) case *issues.Label: - return convertForgejoLabelToF3Path(ctx, o) + return getF3PathOfLabel(ctx, o) case *issues.Milestone: - return convertForgejoMilestoneToF3Path(ctx, o) + return getF3PathOfMilestone(ctx, o) case *issues.Review: - return convertForgejoReviewToF3Path(ctx, o) + return getF3PathOfReview(ctx, o) default: - err := fmt.Errorf("ConvertForgejoToF3Path unexpected type %v %T when converting a Forgejo resource to a F3 path", some, some) + err := fmt.Errorf("GetF3PathOfResource unexpected type %v %T when converting a Forgejo resource to a F3 path", some, some) log.Error(err.Error()) return "", err } diff --git a/services/f3/util/path_test.go b/services/f3/util/path_test.go index 7faf9ee70e..4fddaf12d6 100644 --- a/services/f3/util/path_test.go +++ b/services/f3/util/path_test.go @@ -20,12 +20,12 @@ import ( func assertConvert[T any](t *testing.T, expected string, some T) { t.Helper() - actual, err := ConvertForgejoToF3Path(t.Context(), some) + actual, err := GetF3PathOfResource(t.Context(), some) require.NoError(t, err) assert.Equal(t, expected, actual) } -func TestConvertForgejoToF3Path(t *testing.T) { +func TestGetF3PathToResource(t *testing.T) { require.NoError(t, unittest.PrepareTestDatabase()) t.Run("user", func(t *testing.T) { user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})