cosmin / stashy Goto Github PK
View Code? Open in Web Editor NEWPython API client for the Atlassian Stash REST API
License: Other
Python API client for the Atlassian Stash REST API
License: Other
I'd like to use other core api version like 2.0
,
I tried below code, but without luck:
from stashy.client import StashClient
import stashy
StashClient.core_api_version = '2.0'
s= stashy.connect('http://git.example.com', 'admin', 'foobar')
s.admin.groups.url()
s.admin.groups.url()
still returns 1.0
An import is missing in the file that deals with pull-requests. See this pull-request: #36
I have pulled the latest changes and am using my own Python script to work with Atlassian Stash.
When I do:
commits = stash.projects[PROJECT].repos[REPO].commits()
print commits
I get the following output:
TypeError: commits() takes at least 2 arguments (1 given)
Reading through the source it is not clear to me what argument should be given to the commits() function. I have tried several commit hashes but none of them work. Many other calls do work when I use your library, such as:
branches = stash.projects[PROJECT].repos[REPO].branches()
print branches
I was hoping you could clear this up for me. Thanks!
Thank you very much for stashy! It was easy to get started and has really helped us.
Could we please get new release on pip? The last one is from Feburary 2018,
and we would like to use newer features like the support for auth tokens that were introduced later.
Thank you!
The API endpoints for the 1.0 API seem to have been removed in one of the Bitbucket Server releases. There are now a couple endpoints under the 2.0 version namespace. Is a PR supporting the new endpoints for branch permissions welcome?
Is it possible to get an example of how the pagination helper works when attempting to retrieve all branches? Still fairly new to python, and don't understand how to pass in the start.
Or, it would be great if i could set the limit value in the branch method in the return. I'm trying to not have to modify this module.
return self._client.get(self.url('/branches'+'?limit=10000'), params=params)
Hello there,
Is there any example of this API usage to list the content of a specific branch and get listing of files in each directory inside a branch ?
Thanks
I cannot find an option to remove branch for merge() procedure
please add it
Can somebody give me a example of the usage if the build notification ?
I tried to call the method like this:(Is there a problem with my implementation ?)
stash.builds
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'Stash' object has no attribute 'builds'
I am expecting a replay。
Stashy 0.5 version does not install with python 2.7
pip install stashy
'Collecting stashy Downloading stashy-0.5.tar.gz Complete output from command python setup.py egg_info: error in stashy setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Expected version spec in enum34 ; python_version < '3.4' at ; python_version < '3.4'
Pip Version: 9.0.1
Python Version: 2.7.10
running:
#!/usr/bin/python
import sys
import os
import stashy
stash = stashy.connect("https://stash.***.co.uk/projects/*REPO*", "", "")
for repo in stash.projects[sys.argv[1]].repos.list():
for url in repo["links"]["clone"]:
if (url["name"] == "ssh"):
os.system("git clone %s" % url["href"])
break
Getting
Traceback (most recent call last):
File "./stashy.py", line 4, in
import stashy
File "/stashy.py", line 6, in
stash = stashy.connect("https://stash.***.co.uk/", "", "")
AttributeError: 'module' object has no attribute 'connect'
Please help
I spent a while banging my head on this so it might be worth updating the documentation -
I was trying to update a project description and it was reporting no error, but was not updating the project. After some trial and error I realized my problem - I was running:
project = stash.projects.get('TEST')
project.update(description='stashy test')
when what I needed to be doing was:
project - stash.projects['TEST']
project.update(description='stashy test')
Since the get returns a dict, update is a valid command and it reports success. Inspecting the 'project' object showed the update, but of course it wasn't actually sending anything to the server. It's perfectly valid behavior, just wasn't what I was expecting based on the description in the API - an example of an update call in the docs would have saved me some puzzlement.
Self-signed SSL certificates are not supported by stashy but are supported by the requests library, see: http://docs.python-requests.org/en/latest/user/advanced/#ssl-cert-verification.
stashy.connect()
should allow verify=False (and cert as well) to be supplied to requests.
Hello,
I am trying to remove all permissions from the user , but for some reason there is no error and effect after running the command below:
import stashy
stash = stashy.connect("***", "***", "***")
users = stash.admin.permissions.users.revoke('dg_test')
print users # prints "True"
Thanks,
DG
I'm trying to list the repos that have default branch as develop. Any help on this is appreciated.
As a user I would like to connect to the BitBucket server and retrieve all repos by using a stored SSH Key, (I suspect via a key-id), instead of username/password -- however, I can't figure out how to do that.... can you help?
For instance:
stash.connect("example.com", "admin", "password")
is shown as an example -- but what if I wanted to use an SSH Key instead?
Thanks for any/all of your help regarding this.
Apologies in advance, this is a question vs. a software issue.
How does pagination work? For example, if I'd like to see all the branches in a repo, I can make the following query, and it returns a dict with the first page of 25 results. How do I get the rest?
type(stashyinstance)
class 'stashy.client.Stash'
stashyinstance.projects['myproject'].repos['myrepo'].branches()
{dict of results goes here}
How do I get subsequent result pages?
Edit:
Actually branches() is currently broken:
projects['projectname'].repos['myrepo'].branches()
In maybe_throw
File: "stashy/errors.py"
Source:
29 | def maybe_throw(response):
30 *| if not response.ok:
31 | if response.status_code == 404:
Arguments:
response:
File "stashy/errors.py", line 30, in maybe_throw
exceptions.AttributeError, 'generator' object has no attribute 'ok'
Pull request here should resolve it:
#27
I am able to access my stash repo, but I am always getting this error whether I call get_commit, or browse, or files. I know I am in my repo because repo.get() works. However, I am now trying to pull json files but everytime I call browse(), I get the above error. Please help, been stuck for a long time
I am trying to use the code added in #33 (and later on add POST support to it - see https://github.com/grzegorz-dubicki/stashy/tree/more-ssh).
This code works:
print "%s" % self.bitbucket.ssh.list('gdubicki')
[{u'text': u'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEAyzlZRkspi4fTtxopqxApGymeZ3z16chlZmjEbjiYMNSPHztyf8dQmO7oPXrG+spDcBgMX3k4iLJzy/F7DFm91A4qd9xhKYeMBwYonGXtrNE(...)
..but when I am trying to use the get
method directly then - perhaps because I don't know how to do it correctly - I get HTTP 405 errors:
print "%s" % self.bitbucket.ssh.get('gdubicki')
<Response [405]>
Am I doing it wrong or is it broken?
Python 3.3 support ruins our ability to select requirements based on python version. Ironically, this means we can't choose to install the back-ported enum34 package for python versions under 3.4. When this package is installed on python 3.6, it causes significant issues.
list(stash.projects[PROJECT].repos[REPO].pull_requests.commits()) return an error
s = list(stash.projects[_STASH_URL_MAPS[code_base][0]].repos[_STASH_URL_MAPS[code_base][1]].pull_requests.commits())
AttributeError: 'PullRequests' object has no attribute 'commits'
Stashy is a pretty handy way to interact with Stash, and I've been trying to use it as the basis for adding Stash support to https://github.com/guykisel/inline-plz. However, the version currently hosted on PyPI is very outdated, and does not contain recent bug fixes and improvements needed to make this work.
I would be quite grateful if you could update the PyPI hosted package.
Hello All,
I wanted to know if I can see all the merged Pull request relates to a repository. Can someone tell me if there exists a function for that? or can we take it as a feature requests.
I'm having difficulty in getting a list of branch names for a given repo.
for repo in stash.repos:
pp.pprint( repo )
pp.pprint( stash.repos[ repo[ 'slug' ] ].get_all_branches(items=5) )
sys.exit("done")
TypeError: the JSON object must be str, not 'bytes'
for repo in stash.repos:
pp.pprint( repo )
pp.pprint( stash.repos[ repo[ 'slug' ] ].branches() )
sys.exit("done")
<generator object ResourceBase.paginate at 0x110b18a98>
What am I doing wrong?
Stashy does not support:
https://developer.atlassian.com/static/rest/stash/3.0.1/stash-rest.html#idp250960
Since the function Repository#create_branch adds the prefix "refs/heads/%s" to the origin branch name, it's impossible to create a branch from tags
I would like stashy to be able to have get and post functionality for the "allow forks" setting.
I have already added this to the local copy of stashy I work on and would like to add this to the open-source version. From my understanding, the best way to go about this is to make an issue then open a pull request, so that is how I am proceeding. Let me know if there is a better way.
I am trying to list my project repo's but i am getting an NotFoundException
I am new to python and messing around with bitbucket to get repository/projects names and their owner details.
I am using python virtualenv to run stashy and code below to test utility
import stashy
import getpass
pswd = getpass.getpass('Password:')
stash = stashy.connect("https://bitbucket.companyname.com/stash", "username", pswd)
PROJECT=input("Enter Project Name:")
stash.projects.list()
#stash.projects[PROJECT].repos.list()
#stash.admin.users.list(filter="admin")
Exception
File "teststashy.py", line 11, in <module>
stash.projects.list()
File "/home/yashwanth/.venv/BBAutomation/lib/python3.7/site-packages/stashy/helpers.py", line 107, in list
return list(self.all())
File "/home/yashwanth/.venv/BBAutomation/lib/python3.7/site-packages/stashy/helpers.py", line 74, in paginate
maybe_throw(response)
File "/home/yashwanth/.venv/BBAutomation/lib/python3.7/site-packages/stashy/errors.py", line 41, in maybe_throw
raise NotFoundException(response)
stashy.errors.NotFoundException: Not found: https://bitbucket.companyname.com/stash/rest/api/1.0/projects
What and where am I missing?
Hi there,
in stashy/permissions.py (lines 127 and 161), 'revoke' apis call http post when they're supposed to call http delete
Result: 405 not allowed is thrown by Stash / Bitbucket
The requests library supports SSL client certificates, proxies and timeout controls. It would be handy to allow all of those things to be configured through stashy as well.
audit/1.0/projects/{projectKey}/events
audit/1.0/projects/{projectKey}/repos/{repositorySlug}/events
These two api not listed in README, even in 'not implemented' api list
The README states that you can install stashy with pip but it doesn't seem to be available. On PyPI.
It looks like you have the majority of the things in place in order to publish it. You need to put a tag on v0.1 and point setup.py to the download url then upload it.
This would greatly improve usability and accessibility of Stashy. Thanks!
http://peterdowns.com/posts/first-time-with-pypi.html
https://python-packaging-user-guide.readthedocs.org/en/latest/tutorial.html#creating-your-own-project
(This is related to #65)
Either I don't know how to use that code or the following methods of ssh.py
don't work:
print "%s" % self.bitbucket.ssh[user]
returns:
(...)
TypeError: __init__() takes exactly 4 arguments (5 given)
..with no username provided:
print "%s" % self.bitbucket.ssh.list()
and
for x in self.bitbucket.ssh.all():
print "!!!%s" % x
..return empty list/no output, while the same with my username provided return my key.
Pip log:
Downloading/unpacking stashy
Getting page https://pypi.python.org/simple/stashy/
URLs to search for versions for stashy:
* https://pypi.python.org/simple/stashy/
Analyzing links from page https://pypi.python.org/simple/stashy/
Found link https://pypi.python.org/packages/source/s/stashy/stashy-0.1.tar.gz#md5=a34b25f50ed7afaca2097d2083583683 (from https://pypi.python.org/simple/stashy/), version: 0.1
Downloading stashy-0.1.tar.gz
Downloading from URL https://pypi.python.org/packages/source/s/stashy/stashy-0.1.tar.gz#md5=a34b25f50ed7afaca2097d2083583683 (from https://pypi.python.org/simple/stashy/)
Running setup.py (path:c:\users\cau\appdata\local\temp\pip_build_cau\stashy\setup.py) egg_info for package stashy
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "c:\users\cau\appdata\local\temp\pip_build_cau\stashy\setup.py", line 10, in <module>
long_description=read('README.rst'),
File "c:\users\cau\appdata\local\temp\pip_build_cau\stashy\setup.py", line 5, in read
return open(os.path.join(os.path.dirname(__file__), fname)).read()
IOError: [Errno 2] No such file or directory: 'c:\\users\\cau\\appdata\\local\\temp\\pip_build_cau\\stashy\\README.rst'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "c:\users\cau\appdata\local\temp\pip_build_cau\stashy\setup.py", line 10, in <module>
long_description=read('README.rst'),
File "c:\users\cau\appdata\local\temp\pip_build_cau\stashy\setup.py", line 5, in read
return open(os.path.join(os.path.dirname(__file__), fname)).read()
IOError: [Errno 2] No such file or directory: 'c:\\users\\cau\\appdata\\local\\temp\\pip_build_cau\\stashy\\README.rst'
----------------------------------------
Cleaning up...
Removing temporary dir c:\users\cau\appdata\local\temp\pip_build_cau...
Command python setup.py egg_info failed with error code 1 in c:\users\cau\appdata\local\temp\pip_build_cau\stashy
Exception information:
Traceback (most recent call last):
File "c:\Python27\lib\site-packages\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "c:\Python27\lib\site-packages\pip\commands\install.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "c:\Python27\lib\site-packages\pip\req.py", line 1229, in prepare_files
req_to_install.run_egg_info()
File "c:\Python27\lib\site-packages\pip\req.py", line 325, in run_egg_info
command_desc='python setup.py egg_info')
File "c:\Python27\lib\site-packages\pip\util.py", line 697, in call_subprocess
% (command_desc, proc.returncode, cwd))
InstallationError: Command python setup.py egg_info failed with error code 1 in c:\users\cau\appdata\local\temp\pip_build_cau\stashy
The ability to create / delete tags was added in Stash 3.7.1: STASH-4128
Documentation:
POST: https://developer.atlassian.com/static/rest/stash/latest/stash-scm-git-rest.html#idp7360
DELETE: https://developer.atlassian.com/static/rest/stash/latest/stash-scm-git-rest.html#idp27856
Some new APIs used to work with branches have been introduced (documented here)
So far, only a few methods are available:
For some reason, they are in a separate namespace (/rest/branch-utils/1.0 instead of /rest/api/1.0).
I am unable to retrieve commits. Can you please help me with this.
list(stash.projects[PROJECT].repos[REPO].pull_requests.commits())
AttributeError: 'PullRequests' object has no attribute 'commits'
stash.projects[PROJECT].repos[REPO].commits()
I actually want to retrieve all the commits in a repo. Can you please help me with this. Thank you.
Here https://github.com/cosmin/stashy/blob/master/stashy/repos.py#L143 should be used paginate() instead of self._client.get, as tags/ is a paginated endpoint.
Coudn't find the info in documentation.
Is it possible to create webhooks for repositories using this library ?
See Atlassian's documentation:
https://developer.atlassian.com/bitbucket/server/docs/latest/how-tos/updating-build-status-for-commits.html
Stashy should support both POST and GET methods for this API.
Can we get a new build pushed to pypi? Using this package right now is tough and getting a proper package posted to the public pypi server would solve a lot of issues.
I am trying to create repo using Repo.create(). Is there any option to pass project details in this function.
Please implement the branch permssions api
https://developer.atlassian.com/static/rest/stash/latest/stash-branch-permissions-rest.html
Hi,
I am trying to make call for "/projects/{projectKey}/permissions/users" [GET], which is listed as implemented, but running into some issues. I have installed stashy in my local and I can make other calls as mentioned in example but, I am running into issues when trying to get the list of authenticated users at the project level. Can someone please let me know what is the correct call for this? I have tried following calls, but couldn't get it working.
project = stash.projects['TEST_PROJECT'].permissions()
and
project = stash.projects['TEST_PROJECT'].repos['test'].permissions()
Error for (project = stash.projects['TEST_PROJECT'].permissions())
$ ./user-audit.py
Reteriving TEST_PROJECT project from stash!
Traceback (most recent call last):
File "./user-audit.py", line 31, in
get_project()
File "./user-audit.py", line 13, in get_project
project = stash.projects['TEST_PROJECT'].permissions()
TypeError: 'ProjectPermissions' object is not callable
Error for (project = stash.projects['TEST_PROJECT'].repos['test'].permissions())
$ ./user-audit.py
Reteriving TEST_PROJECT project from stash!
Traceback (most recent call last):
File "./user-audit.py", line 31, in
get_project()
File "./user-audit.py", line 13, in get_project
project = stash.projects['TEST_PROJECT'].repos['test'].permissions()
TypeError: 'Permissions' object is not callable
Hi:
I am using Python 3.6.8. I got the error cannot import name 'decorator' when I import stashy.
Do you have any idea how to fix it?
Trying to update a project using project.update(). I'm not entirely sure what the 'project' argument is but I figured that it is either the id or the key. Neither works. Getting TypeError in both cases. Any idea?
project_id = self.connection.projects[MYKEY].get()['id']
new_description = 'testing adding description...'
Traceback (most recent call last):
File "./stash.py", line 65, in <module>
main()
File "./stash.py", line 61, in main
s.add_to_description('testing adding description...')
File "./stash.py", line 54, in add_to_description
self.connection.projects[MYKEY].update(project_id, description=new_description)
File "<string>", line 2, in update
File "build/bdist.linux-x86_64/egg/stashy/errors.py", line 53, in response_or_error
File "build/bdist.linux-x86_64/egg/stashy/errors.py", line 35, in maybe_throw
File "build/bdist.linux-x86_64/egg/stashy/errors.py", line 25, in __init__
TypeError: cannot concatenate 'str' and 'int' objects
Since version 5.2 bitbucket implemented a function which allows one to enable hooks on project level which is then inherited down to all repositories. This functionality exists in the rest API see the following link.
https://docs.atlassian.com/bitbucket-server/rest/5.2.3/bitbucket-rest.html#idm45417675536720
We need this function and would greatly appreciate if it is implemented.
/Oskar
Hi,
As fas as I can see, the repo permissions features are not in the implemented/not implemented features.
Do you guys have any plans to add this?
http://example.com/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/permissions
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.