Skip to content
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

Add support for getting and replacing topics on a repository #634

Closed
peterkline opened this issue Sep 21, 2017 · 23 comments
Closed

Add support for getting and replacing topics on a repository #634

peterkline opened this issue Sep 21, 2017 · 23 comments

Comments

@peterkline
Copy link

Topics are a fairly new feature within Github. Currently this functionality is provided in the API in a beta mode. We have a need to use these to add attributes and then consume them for automation. Hopefully this helps others.

API Documentation:
List topics in a repo
Replace topics in a repo

Examples of use:

# Get list of topics from a repository    
topics = repo_obj.get_topics()

# Replace current (if there are any) topics with list
repo_obj.replace_topics(['base', 'personal', 'playground'])
@TheVetter
Copy link

Has topics support been added?

@sfdye
Copy link
Member

sfdye commented Apr 5, 2018

@TheVetter Should be soon, I have reviewed the PR and still waiting response for the original author @peterkline

@migueleliasweb
Copy link

migueleliasweb commented Apr 6, 2018

While this issue is not fixed, we should be able to access the topics with the _rawData, right ?

@sfdye
Copy link
Member

sfdye commented Apr 6, 2018

@migueleliasweb I am afraid not, as it requires calling another endpoint. (/topics) However, I will try to get this merged soon.

@migueleliasweb
Copy link

I thought the same but apparently the topics list is returned from the repo itself. Ps: Dunno if this was a recent change on the API itself.

See: https://developer.github.com/v3/repos/#get

@sfdye
Copy link
Member

sfdye commented Apr 6, 2018

@migueleliasweb You are right, the topics attributes is currently in preview, but to edit the attributes we still need to go back to /topics endpoint.

@migueleliasweb
Copy link

@sfdye I just wanted to list them =/

Anyway... I seem unable to get them even accessing the _rawData directly. See:

ipdb> ll
    643     def get_repo(self, name):
    644         """
    645         :calls: `GET /repos/:owner/:repo <http://developer.github.com/v3/repos>`_
    646         :param name: string
    647         :rtype: :class:`github.Repository.Repository`
    648         """
    649         assert isinstance(name, str), name
    650         headers, data = self._requester.requestJsonAndCheck(
    651             "GET",
    652             "/repos/" + self.login + "/" + name
    653         )
--> 654         return github.Repository.Repository(self._requester, headers, data, completed=True)
    655 

ipdb> data["topics"]
*** KeyError: 'topics'

@sfdye
Copy link
Member

sfdye commented Apr 6, 2018

@migueleliasweb You're missing the custom header application/vnd.github.mercy-preview+json. I guess this is new so the master doesn't have it yet.

@migueleliasweb
Copy link

@sfdye Pardon me, I totally missed that !

@edanhauon
Copy link

Hi @sfdye
How soon is soon?

I ask since My app is dependent on this matter - and if it won't happen soon we'll have to develop this ourselves.

Your help is much appreciated 👍.

Edan

@sfdye
Copy link
Member

sfdye commented Apr 13, 2018

@edanhauon The original author is not responding, so if you could open a new PR I am happy to review and cut a new version once that's merged.

@edanhauon
Copy link

Could you maybe add me to the current PR so I could what has been done already?

Thanks,
Edan

@sfdye
Copy link
Member

sfdye commented Apr 13, 2018

@edanhauon what do you mean?

@edanhauon
Copy link

@sfdye never mind, I see it in this thread. thanks.

@peterkline
Copy link
Author

Sorry guys for not being around. Been buried with work related coding. if you can't wait for about 12 hours for me to make any mods and redo the PR then by all means fork off whats here. If you can wait I will finish the coding.

@sfdye
Copy link
Member

sfdye commented Apr 13, 2018

@peterkline I can wait

@edanhauon
Copy link

@peterkline same :)

@wyardley
Copy link
Contributor

Patch works for me, with the notes mentioned in the PR, that is, it would be a little more user-friendly if you can pass that array back rather than having to send it as {'name': topics}, so like so:

topics = repo.get_topics()
topics.append('foobar')
repo.replace_topics(data)

vs

topics = repo.get_topics()
topics.append('foobar')
data = {'names': topics}
repo.replace_topics(data)

@sfdye
Copy link
Member

sfdye commented Apr 20, 2018

@wyardley suggestion accepted

@sfdye
Copy link
Member

sfdye commented May 4, 2018

Anyone care to get this thing moving? Topic is a stable feature now, I wanna make it happen!

@stale
Copy link

stale bot commented Jul 5, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 5, 2018
wyardley pushed a commit to wyardley/PyGithub that referenced this issue Jul 5, 2018
@wyardley
Copy link
Contributor

wyardley commented Jul 5, 2018

I'm proposing #832, which resolves the test failure, and I think resolves most of this feedback? It also switches the input to replace_topics() to the expected array as discussed. Would appreciate feedback, esp. on the test case I added.

@stale stale bot removed the wontfix label Jul 5, 2018
sfdye pushed a commit that referenced this issue Jul 6, 2018
* Add support for getting and replacing topics on a repository #634

* Add / fix tests, accept list vs dict for replace_topics (#634)
@sfdye
Copy link
Member

sfdye commented Jul 6, 2018

Merged in #832 thanks to @wyardley and credits to @peterkline for the original PR 🎉

@sfdye sfdye closed this as completed Jul 6, 2018
candrikos pushed a commit to candrikos/PyGithub that referenced this issue Sep 25, 2020
* Add support for getting and replacing topics on a repository PyGithub#634

* Add / fix tests, accept list vs dict for replace_topics (PyGithub#634)
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

No branches or pull requests

6 participants