8000 implement support for Forgejo comments and reactions by julietowah · Pull Request #906 · packit/ogr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

implement support for Forgejo comments and reactions #906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

julietowah
Copy link
@julietowah julietowah commented Mar 24, 2025

Implement Support for Forgejo Comments and Reactions

Description:
This PR introduces support for handling comments and reactions within Forgejo. The changes include implementing classes for managing issue comments, pull request comments, commit comments, and their associated reactions. The implementation follows the structure of the existing ogr framework while integrating Forgejo API functionalities.

Changes in this PR:

  1. Created the comments.py file in ogr/services/forgejo

  2. Added ForgejoReaction class

    • Supports adding and deleting reactions to comments.
    • Retrieves reactions for a given comment.
    • Extracts user login and content from Forgejo's API response.
  3. Added ForgejoComment class

    • Allows retrieving, editing, and updating comments.
    • Supports fetching associated reactions.
    • Provides structured access to comment metadata (author, timestamps, etc.).
  4. Added Specialized Comment Classes:

    • ForgejoIssueComment: Represents comments on issues.
    • ForgejoPRComment: Represents comments on pull requests.
    • ForgejoCommitComment: Represents comments on commits.

fixes #883

Copy link
Contributor

@julietowah
Copy link
Author
julietowah commented Mar 25, 2025

Please @morucci @lbarcziova i tried to add mergeit label but it seems i don't have the necessary permission.

@julietowah julietowah marked this pull request as draft March 25, 2025 12:55
@julietowah julietowah marked this pull request as ready for review March 25, 2025 13:01
Copy link
@LecrisUT LecrisUT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original issue is about implementation for forgejo please implement it there first 1. The generalisation in the abstract is a more difficult task that requires some refactoring.

Footnotes

  1. https://github.com/packit/ogr/tree/main/ogr/services/forgejo

recipe.yaml Outdated
@@ -27,6 +27,7 @@
name:
- twine # we need newest twine, b/c of the check command
- readme_renderer[md]
- pytest-cov

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you open a separate PR for this? I think it would be better to drop the default --cov flags and create a separate test environment that would integrate with codecov or such.

Copy link
@LecrisUT LecrisUT Apr 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to rebase onto main. This change has been incorporated in #893 (learning opportunity to get some intuition of what git rebase does and how to handle its conflicts 🙂)

ogr/abstract.py Outdated

def __str__(self):
return f"Reaction(raw_reaction={self._raw_reaction})"

def delete(self) -> None:
"""Delete a reaction."""
raise NotImplementedError()
if not self._id:
raise ValueError("Cannot delete a reaction without an ID.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clashes with reaction_id being optional. If the intent is that id is always present then there should be an overwritable @property with the default being to read self._id or raise.

ogr/abstract.py Outdated
raw_reaction: Any,
reaction_id: Optional[int] = None,
parent: Optional[Any] = None,
) -> None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation would be appreciated. No idea what parent is meant to be.

ogr/abstract.py Outdated
self._body = raw_comment["body"]
self._author = raw_comment["user"]["login"]
self._created = raw_comment["created_at"]
self._edited = raw_comment.get("updated_at")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is a strong assumption. Either make the type-hinting of raw_comment more explicit or let it be overwritten in the actual implementation. Same for the other parts.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thank you am on it

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to double check. I am not recommending to tackle type-hinting approach in this PR (maybe in a separate one). Instead you should try to implement it in the /ogr/services/forgejo files first.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok i will

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also drop the changes made in abstract.py. I saw you dropped some with a33e90e, but the remaining changes should also be dropped for now.

@julietowah julietowah changed the title implement methods for the classes inheriting from Comment and Reaction https://github.com/packit/ogr/issues/883 implement methods for the classes inheriting from Comment and Reaction Mar 27, 2025
@julietowah julietowah changed the title implement methods for the classes inheriting from Comment and Reaction implement support for Forgejo comments and reactions Mar 27, 2025
Copy link
Contributor

@julietowah julietowah force-pushed the feature/implement-comment-reaction branch from e7f684e to 93d476d Compare April 1, 2025 14:42
Copy link
Contributor

Copy link
Member
@lbarcziova lbarcziova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot for having a look into this!

To clarify the code structure, the ogr/abstract.py should not be changed anyhow, it just holds the interface that is then implemented for particular forges in respective directories in ogr/services (e.g. github). So can you please move the implementation here, creating new files? You can check how it is done for other forges e.g. https://github.com/packit/ogr/tree/main/ogr/services/github and also having a look into implementation in ogr/services/forgejo can be helpful. Let me know if this is clear!

ogr/abstract.py Outdated
Comment on lines 64 to 68
ex: Union[
github.GithubException,
gitlab.GitlabError,
pyforgejo.core.api_error.ApiError,
],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these changes related to exceptions were not intended, or?

Copy link
Author
@julietowah julietowah Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, for the unintended change. I'll work on them and push an update. Please hold off on reviewing until I fix it. Thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this came from when i pull recent changes from the before i pushed to the pr

@julietowah
Copy link
Author
julietowah commented Apr 2, 2025

#906 (review)

Thank you so much,

You mean i should create a file and impliment the logic at https://github.com/packit/ogr/tree/main/ogr/services/forgejo following the examples at https://github.com/packit/ogr/tree/main/ogr/services/github

@julietowah
Copy link
Author

Hello @lbarcziova i want to create a pr for this implementation but i want to use a new pr altogether.
will it be okay?

@LecrisUT
Copy link
LecrisUT commented Apr 3, 2025

Generally it is preferred to rebase and continue in the same PR in order to keep the discussion history, but if you feel like you need a fresh start at it, then you can restart it, as long as you do not do it excessively that it would confuse people.

To me the discussions so far have been quite minimal and I wouldn't do a fresh start yet (reviews can easily get to ~100 comments and I still go back to those comments every now and then). Instead, you can mark conversations as resolved, and I sometimes mark my own comments when I feel it is outdated.

@julietowah
Copy link
Author

Ok thank you

Copy link
Contributor

@julietowah julietowah force-pushed the feature/implement-comment-reaction branch from afa6147 to 381972a Compare April 5, 2025 14:03
Copy link
Contributor

@julietowah
Copy link
Author

Hello ,
I think its all good now

Copy link
@LecrisUT LecrisUT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest you either try:

  • work locally similar to the github example in the readme, but instead use codeberg and for example try to read the reactions on this issue. Or better yet, open up a test repo for you to play with and try the whole read+write api (be a good netizen and don't test write on other people's public repos)
  • or see the test-suite and reimplement the github comments tests in the form of the forgejo tests

forgejo_client: Any,
repository: str,
issue_number: int,
) -> None:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this __init__ come from. I don't see a reference to forgejo_client in the current codebase

@julietowah
Copy link
Author

I would suggest you either try:

  • work locally similar to the github example in the readme, but instead use codeberg and for example try to read the reactions on this issue. Or better yet, open up a test repo for you to play with and try the whole read+write api (be a good netizen and don't test write on other people's public repos)
  • or see the test-suite and reimplement the github comments tests in the form of the forgejo tests

Ok let me work on it

Copy link
Member
@lbarcziova lbarcziova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a closer look at the PR, this functionality unfortunately depends a bit on the implementation of the ForgejoPullRequest and ForgejoIssue class. To be able to actually access the comments (=> and reactions), also the get_comment and _get_all_comments need to be implemented for both of them, see example in Gitlab implementation here and here.

Comment on lines +44 to +48
url = (
f"{self._forgejo_client.forgejo_url}/api/v1/repos/"
f"{self._repository}/issues/{self._issue_number}/reactions/{self._id}"
)
self._forgejo_client._make_request("DELETE", url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are using the client library methods, see examples here, that file can be an inspiration on how to implement the methods. So for this particular case, you would use this method. And similarly, for other methods where you currently construct the URL manually.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for this clarity

Copy link
Contributor
@mynk8 mynk8 Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am working on implementing ForgejoIssue (#896) and it also depends on ForgejoIssueComments, I can collaborate to complete this PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @mynk8 will you have time today?

Copy link
Contributor
@mynk8 mynk8 Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes 👍

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the dependency be the other way around? Have this PR depend on #896? One simple approach is to rebase this on top of #896 and update it as the PR evolves. This is also a good example why you should have a concise git history

Copy link
Contributor
@mynk8 mynk8 Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kind of true, I need ForgejoIssueComments for get_comments and _get_all_comments and this is where I think I can help with here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, I missed that this PR is now implementing comments in general. Up to you how it is easier to coordinate. You could also make it a NotImplementedError and follow it up in a subsequent PR. No need to implement everything in a single PR, as long as the minimal functionality can be tested

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.

Implement support for Forgejo comments and reactions on it
4 participants
0