File: package.go

package info (click to toggle)
golang-code-gitea-sdk 0.17.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 760 kB
  • sloc: makefile: 107
file content (93 lines) | stat: -rw-r--r-- 3,202 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2023 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package gitea

import (
	"fmt"
	"time"
)

// Package represents a package
type Package struct {
	// the package's id
	ID int64 `json:"id"`
	// the package's owner
	Owner User `json:"owner"`
	// the repo this package belongs to (if any)
	Repository *string `json:"repository"`
	// the package's creator
	Creator User `json:"creator"`
	// the type of package:
	Type string `json:"type"`
	// the name of the package
	Name string `json:"name"`
	// the version of the package
	Version string `json:"version"`
	// the date the package was uploaded
	CreatedAt time.Time `json:"created_at"`
}

// PackageFile represents a file from a package
type PackageFile struct {
	// the file's ID
	ID int64 `json:"id"`
	// the size of the file in bytes
	Size int64 `json:"size"`
	// the name of the file
	Name string `json:"name"`
	// the md5 hash of the file
	MD5 string `json:"md5"`
	// the sha1 hash of the file
	SHA1 string `json:"sha1"`
	// the sha256 hash of the file
	SHA256 string `json:"sha256"`
	// the sha512 hash of the file
	SHA512 string `json:"sha512"`
}

// ListPackagesOptions options for listing packages
type ListPackagesOptions struct {
	ListOptions
}

// ListPackages lists all the packages owned by a given owner (user, organisation)
func (c *Client) ListPackages(owner string, opt ListPackagesOptions) ([]*Package, *Response, error) {
	if err := escapeValidatePathSegments(&owner); err != nil {
		return nil, nil, err
	}
	opt.setDefaults()
	packages := make([]*Package, 0, opt.PageSize)
	resp, err := c.getParsedResponse("GET", fmt.Sprintf("/packages/%s?%s", owner, opt.getURLQuery().Encode()), nil, nil, &packages)
	return packages, resp, err
}

// GetPackage gets the details of a specific package version
func (c *Client) GetPackage(owner, packageType, name, version string) (*Package, *Response, error) {
	if err := escapeValidatePathSegments(&owner, &packageType, &name, &version); err != nil {
		return nil, nil, err
	}
	foundPackage := new(Package)
	resp, err := c.getParsedResponse("GET", fmt.Sprintf("/packages/%s/%s/%s/%s", owner, packageType, name, version), nil, nil, foundPackage)
	return foundPackage, resp, err
}

// DeletePackage deletes a specific package version
func (c *Client) DeletePackage(owner, packageType, name, version string) (*Response, error) {
	if err := escapeValidatePathSegments(&owner, &packageType, &name, &version); err != nil {
		return nil, err
	}
	_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/packages/%s/%s/%s/%s", owner, packageType, name, version), nil, nil)
	return resp, err
}

// ListPackageFiles lists the files within a package
func (c *Client) ListPackageFiles(owner, packageType, name, version string) ([]*PackageFile, *Response, error) {
	if err := escapeValidatePathSegments(&owner, &packageType, &name, &version); err != nil {
		return nil, nil, err
	}
	packageFiles := make([]*PackageFile, 0)
	resp, err := c.getParsedResponse("GET", fmt.Sprintf("/packages/%s/%s/%s/%s/files", owner, packageType, name, version), nil, nil, &packageFiles)
	return packageFiles, resp, err
}