Skip to content

Add Label functionality#36

Open
luanmingyi wants to merge 1 commit intoLangenfeld:masterfrom
luanmingyi:feat-labels
Open

Add Label functionality#36
luanmingyi wants to merge 1 commit intoLangenfeld:masterfrom
luanmingyi:feat-labels

Conversation

@luanmingyi
Copy link
Copy Markdown

  • Add methods for creating and retrieving labels in the Organization and Repository classes
  • Add methods for retrieving and setting labels in the Issue class
  • Introduce a new Label class to represent label objects
  • Add some parsing information to Issue
  • Update related imports and API object lists

tested with api 1.21.0

test code:

from gitea import (
    Gitea,
    User,
    Organization,
    Team,
    Repository,
    Branch,
    NotFoundException,
    AlreadyExistsException,
    Issue,
    Milestone,
    Label,
)

def generate_random_color():
    import random
    return "{:06x}".format(random.randint(0, 0xFFFFFF))

def print_label(l):
    print(l.id, l.name, l.color, l.exclusive, l.is_archived)
    print(l.description)
    print(l.url)

gitea = Gitea('https://try.gitea.cn','TOKEN')

print(gitea.get_version())

org = Organization.request(gitea, 'testorg')
l=org.create_label('org-new-label-1', generate_random_color())
l=org.create_label('org-new-label-2', generate_random_color())
l=org.create_label('org-new-label-3', generate_random_color())

repo = Repository.request(gitea, 'testorg', 'testpy')
l=repo.create_label('repo-new-label-1', generate_random_color())
l=repo.create_label('repo-new-label-2', generate_random_color())
l=repo.create_label('repo-new-label-3', generate_random_color())

l = Label.request(gitea, 'testorg', None, 1)
print_label(l)
l = Label.request(gitea, 'testorg', 'testpy', 4)
print_label(l)

for l in org.get_labels():
    print('---o ', l.name)
    l.color = generate_random_color()
    l.commit()

for l in repo.get_labels():
    print('---r ', l.name)
    l.color = generate_random_color()
    l.commit()

issue:Issue = Issue.request(gitea, 'testorg', 'testpy', 1)
for l in issue.labels:
    print('---i ', l.name)

issue.set_labels([org.get_labels()[1],repo.get_labels()[2]])
issue.set_labels([])

print(issue.due_date)
from datetime import datetime,timedelta
issue.due_date = issue.created_at+timedelta(days=5)
issue.commit()

- Add methods for creating and retrieving labels in the Organization and Repository classes
- Add methods for retrieving and setting labels in the Issue class
- Introduce a new Label class to represent label objects
- Add some parsing information to Issue
- Update related imports and API object lists

tested with api 1.21.0
@luanmingyi luanmingyi changed the title feat: Add Label functionality Add Label functionality Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant