@@ -44,7 +44,7 @@ func (cp *GHProvider) Download(ctx context.Context, opts Opts, outputFile string
4444 log .Dbg (fmt .Sprintf ("Download options: %#v" , opts ))
4545
4646 archiveLink , _ , err := cp .client .Repositories .GetArchiveLink (ctx , opts .Owner , opts .Repo ,
47- github .Zipball , & github.RepositoryContentGetOptions {Ref : opts . Ref }, true )
47+ github .Zipball , & github.RepositoryContentGetOptions {Ref : getRunRef ( opts ) }, true )
4848 if err != nil {
4949 return errors .Wrap (err , "failed to download content" )
5050 }
@@ -72,6 +72,16 @@ func (cp *GHProvider) Download(ctx context.Context, opts Opts, outputFile string
7272 return nil
7373}
7474
75+ func getRunRef (opts Opts ) string {
76+ ref := opts .Commit
77+
78+ if ref == "" {
79+ ref = opts .Ref
80+ }
81+
82+ return ref
83+ }
84+
7585// Extract extracts downloaded repository archive.
7686func (cp * GHProvider ) Extract (file string ) (string , error ) {
7787 extractDirNameCmd := fmt .Sprintf ("unzip -qql %s | head -n1 | tr -s ' ' | cut -d' ' -f5-" , file )
@@ -85,14 +95,19 @@ func (cp *GHProvider) Extract(file string) (string, error) {
8595
8696 log .Dbg ("Archive directory: " , string (bytes .TrimSpace (dirName )))
8797
88- resp , err := exec .Command ("unzip" , "-d" , RepoDir , file ).CombinedOutput ()
98+ archiveDir , err := os .MkdirTemp (RepoDir , "*_extract" )
99+ if err != nil {
100+ return "" , err
101+ }
102+
103+ resp , err := exec .Command ("unzip" , "-d" , archiveDir , file ).CombinedOutput ()
89104 log .Dbg ("Response: " , string (resp ))
90105
91106 if err != nil {
92107 return "" , err
93108 }
94109
95- source := path .Join (RepoDir , string (bytes .TrimSpace (dirName )))
110+ source := path .Join (archiveDir , string (bytes .TrimSpace (dirName )))
96111 log .Dbg ("Source: " , source )
97112
98113 return source , nil
0 commit comments