Skip to content

Commit

Permalink
fix(manifest-repo-export-service): Changed fetch from HEAD to direct …
Browse files Browse the repository at this point in the history
…reference (#2055)

The manifest repo export service fetches the reference to the current
commit directly in all of the code base. Updated this fetch the HEAD to
get the specific reference for consistency.
Ref: SRX-B66T2N
  • Loading branch information
diogo-nogueira-freiheit authored Oct 21, 2024
1 parent 51d74ae commit 0a0d0ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions services/manifest-repo-export-service/pkg/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,11 @@ func processEsls(ctx context.Context, repo repository.Repository, dbHandler *db.
}

//Get latest commit. Write esl timestamp and commit hash.
commit, err := repo.GetHeadCommit()
commitId, err := repo.GetHeadCommitId()
if err != nil {
return err
}
return dbHandler.DBWriteCommitTransactionTimestamp(ctx, transaction, commit.Id().String(), esl.Created)
return dbHandler.DBWriteCommitTransactionTimestamp(ctx, transaction, commitId.String(), esl.Created)
})
if err != nil {
err3 := repo.FetchAndReset(ctx)
Expand Down
16 changes: 6 additions & 10 deletions services/manifest-repo-export-service/pkg/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type Repository interface {
StateAt(oid *git.Oid) (*State, error)
FetchAndReset(ctx context.Context) error
PushRepo(ctx context.Context) error
GetHeadCommit() (*git.Commit, error)
GetHeadCommitId() (*git.Oid, error)
}

type TransformerBatchApplyError struct {
Expand Down Expand Up @@ -418,17 +418,13 @@ func (r *repository) PushRepo(ctx context.Context) error {
return nil
}

func (r *repository) GetHeadCommit() (*git.Commit, error) {
ref, err := r.repository.Head()
func (r *repository) GetHeadCommitId() (*git.Oid, error) {
branchHead := fmt.Sprintf("refs/heads/%s", r.config.Branch)
ref, err := r.repository.References.Lookup(branchHead)
if err != nil {
return nil, fmt.Errorf("Error fetching HEAD: %v", err)
return nil, fmt.Errorf("Error fetching reference \"%s\": %v", branchHead, err)
}
commit, err := r.repository.LookupCommit(ref.Target())
if err != nil {
return nil, fmt.Errorf("Error transalting into commit: %v", err)
}
return commit, nil

return ref.Target(), nil
}

func (r *repository) ApplyTransformersInternal(ctx context.Context, transaction *sql.Tx, transformer Transformer) ([]string, *State, []*TransformerResult, *TransformerBatchApplyError) {
Expand Down

0 comments on commit 0a0d0ac

Please sign in to comment.