Skip to content

Commit

Permalink
fix: Ignore rules filtering (#6)
Browse files Browse the repository at this point in the history
Correct ignore rules filtering and group results by repository and then
file.
Correct GitHub cli pull request creation.
  • Loading branch information
nieomylnieja authored Jul 30, 2024
1 parent bcfeb94 commit 9d39d37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ type File struct {
}

type IgnoreRule struct {
RepositoryName *string `json:"fileName,omitempty"`
FileName *string `json:"repositoryName,omitempty"`
RepositoryName *string `json:"repositoryName,omitempty"`
FileName *string `json:"fileName,omitempty"`
Regex *string `json:"regex,omitempty"`
Hunk *diff.Hunk `json:"hunk,omitempty"`
}
Expand Down
15 changes: 9 additions & 6 deletions internal/gitsync/gitsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func Run(conf *config.Config, command Command) error {
}
}
updatedFiles := make(map[*config.Repository][]string, len(conf.Repositories))
for _, file := range conf.SyncFiles {
rootFilePath := filepath.Join(conf.GetStorePath(), conf.Root.Name, file.Path)
for _, syncedRepo := range conf.Repositories {
for _, syncedRepo := range conf.Repositories {
for _, file := range conf.SyncFiles {
rootFilePath := filepath.Join(conf.GetStorePath(), conf.Root.Name, file.Path)
updated, err := syncRepoFile(conf, command, syncedRepo, file, rootFilePath)
if err != nil {
return errors.Wrapf(err, "failed to sync %s repository file: %s", syncedRepo.Name, file.Name)
Expand Down Expand Up @@ -98,7 +98,7 @@ func syncRepoFile(
regexes := make([]string, 0)
for _, ignore := range getIgnoreRules(conf, ignoreRulesQuery{
RepoName: syncedRepo.Name,
FileName: file.Path,
FileName: file.Name,
Regex: true,
}) {
regexes = append(regexes, *ignore.Regex)
Expand Down Expand Up @@ -135,7 +135,7 @@ hunkLoop:
for i, hunk := range unifiedFmt.Hunks {
for _, ignore := range getIgnoreRules(conf, ignoreRulesQuery{
RepoName: syncedRepo.Name,
FileName: file.Path,
FileName: file.Name,
Hunk: true,
}) {
if ignore.Hunk.Equal(hunk) {
Expand Down Expand Up @@ -322,7 +322,10 @@ func openPullRequest(repo *config.Repository, commit *commitDetails) error {
"--title", commit.Title,
"--body", commit.Body,
"--assignee", "@me",
"--base", ref,
// It's vital to remove the "origin/" prefix.
// Otherwise, the GitHub CLI will fail to create a pull request,
// as it can only accept a direct branch name.
"--base", strings.TrimPrefix(ref, "origin/"),
"--head", gitsyncUpdateBranch,
)
if err != nil {
Expand Down

0 comments on commit 9d39d37

Please sign in to comment.