Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1791 from ChistiyKot/support-repositories-archive…
Browse files Browse the repository at this point in the history
…-path

Add repositories archive path support
  • Loading branch information
svanharmelen authored Sep 25, 2023
2 parents 428c125 + fabcd43 commit fd20da1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/repository_archive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Copyright 2021, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package main

import (
"log"

"github.com/xanzy/go-gitlab"
)

func repositoryArchiveExample() {
git, err := gitlab.NewClient("yourtokengoeshere")
if err != nil {
log.Fatal(err)
}

// Get repository archive
opt := &gitlab.ArchiveOptions{
Format: gitlab.String("tar.gz"),
// Gitlab API supports archiving first level directories at the moment, e.g. "mygroup/myproject/mydir".
// If you pass 2+ level directory in path, whole repository will be archived and downloaded.
Path: gitlab.String("mydir"),
}
content, _, err := git.Repositories.Archive("mygroup/myproject", opt, nil)
if err != nil {
log.Fatal(err)
}

log.Printf("Repository archive contains %d byte(s)", len(content))
}
1 change: 1 addition & 0 deletions repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (s *RepositoriesService) RawBlobContent(pid interface{}, sha string, option
// https://docs.gitlab.com/ee/api/repositories.html#get-file-archive
type ArchiveOptions struct {
Format *string `url:"-" json:"-"`
Path *string `url:"path,omitempty" json:"path,omitempty"`
SHA *string `url:"sha,omitempty" json:"sha,omitempty"`
}

Expand Down

0 comments on commit fd20da1

Please sign in to comment.