Skip to content

Commit

Permalink
Add more features (#16)
Browse files Browse the repository at this point in the history
Fix #15
Fix #13 

* Add dynamic attribute from _links

* remove old repsonse.json

* Add Atachment object and download method

* try to fix test

* escape /

* add revisions as property

* Add more docs

* omit test coverage

* duplicate test name

* source dir to coverage

* rtfm codacy manual

* Add docs, deploy on develop\master only

* star repo
  • Loading branch information
allburov authored Jan 9, 2018
1 parent 465b83b commit ca03d8f
Show file tree
Hide file tree
Showing 29 changed files with 667 additions and 543 deletions.
3 changes: 3 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
exclude_paths:
- tests/**
15 changes: 14 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,30 @@ script:
- coverage run -m py.test tests
- coverage xml
- python-codacy-coverage -r coverage.xml

deploy:
provider: pypi
user: devopshq
password:
secure: "u7kqhFT32wLvGvdXLRg3RtTdfGcSzfFWTQb0p1cdRHWBm/771Q2H4bfvwv8GTVmSz+0txtW4O20/VMuMSULqAgW9ChLoNnpppsiEuwOL/KgFknOMgegM+QqdBU7OyB4c0XBxCEfoe8/+Z8lNlB1+UShwh6aJHjiUvR9U537ebtniMWyj0Nb93f53YQGsh29gbuqDNzIWPePFuSDBhKTRhKEHdBfol11YCgyNs2MXkdTUQ60G+DMtdAOM32mJEXi3n2yQWtnWdnsxApqZ4LLlEO1J7FJ0/6sXEd5Y8aQBoYPdE5RdGjo1gjxpp0tL3WxXisG1TlHdgNShKzO5CT4pUFD5qWqhbzlwDM8eI3xFS39I75bVeoPrQ9jn0MlBs8JQJIEFbn6HDW7G/hezMoQPwH2Sn2ET9/XH9axt3U7Wrqf9I10FuFMdBZ4hD62kml94WfxiC40sCNMgYW/zPYGSUQLXfzWImyFz32K8MTQErWVoiaDz8bx5rjLa+zmmwchhZCX4YdBh4BMIOy793YYx6/jLGUBhKuIyHGYREUF/ZlZg5rYssbKUP9G4TdzPix3dGCBgdtrsYwUZ79Odu/SjwV8uzOfcU2p9E0j1GjEK5BnfwY7b5ZpXeagBze34kDU3U89Jnmwc08eu0S+olv7/4iGn+gvQZOvM9s0CShhMI7I="
distributions: sdist bdist_wheel
on:
all_branches: true
branch: master
skip_cleanup: true

deploy:
provider: pypi
user: devopshq
password:
secure: "u7kqhFT32wLvGvdXLRg3RtTdfGcSzfFWTQb0p1cdRHWBm/771Q2H4bfvwv8GTVmSz+0txtW4O20/VMuMSULqAgW9ChLoNnpppsiEuwOL/KgFknOMgegM+QqdBU7OyB4c0XBxCEfoe8/+Z8lNlB1+UShwh6aJHjiUvR9U537ebtniMWyj0Nb93f53YQGsh29gbuqDNzIWPePFuSDBhKTRhKEHdBfol11YCgyNs2MXkdTUQ60G+DMtdAOM32mJEXi3n2yQWtnWdnsxApqZ4LLlEO1J7FJ0/6sXEd5Y8aQBoYPdE5RdGjo1gjxpp0tL3WxXisG1TlHdgNShKzO5CT4pUFD5qWqhbzlwDM8eI3xFS39I75bVeoPrQ9jn0MlBs8JQJIEFbn6HDW7G/hezMoQPwH2Sn2ET9/XH9axt3U7Wrqf9I10FuFMdBZ4hD62kml94WfxiC40sCNMgYW/zPYGSUQLXfzWImyFz32K8MTQErWVoiaDz8bx5rjLa+zmmwchhZCX4YdBh4BMIOy793YYx6/jLGUBhKuIyHGYREUF/ZlZg5rYssbKUP9G4TdzPix3dGCBgdtrsYwUZ79Odu/SjwV8uzOfcU2p9E0j1GjEK5BnfwY7b5ZpXeagBze34kDU3U89Jnmwc08eu0S+olv7/4iGn+gvQZOvM9s0CShhMI7I="
distributions: sdist bdist_wheel
on:
branch: develop
skip_cleanup: true

after_script:
- echo "Deploy to PyPI finished."

env:
global:
- secure: "d67oNhecPXRl0HiTfcI29PKUPLo657VMaCLAt7BAyPk3LXLSgkz9X0fpz0I2dq3DrtREMrKNcoHjFY5x5FoMemYJfg/93PPk8hRbu3XWKiGVHVdj8xwu2hJSSxl/enmEs25qAs1c3Rss+9CyZ7rP4cY7J0hiVymgBZKWSG/8UL6P2D3iDpvxf3EKapPRrf8FP6l3Nmwk3iVlFrwzq4koBUlC2SEd2Hr1uL+iGHuOdNlH4bksMc0nIeC6f905YJ1x3hHMg46h75RkWBrPmj9nn5eAS3jva8Fg9WrDiieF9JrL6GZ0SpektgDS+SjZuinAgjmDZQOogLZtg8+cyDVSud5x0d1K1OQBatNb1ZWVDqLld2E6/6Pxp1x1Bg52OpQvxL23HZkg7XZtxhZzhOEI4f/TvG4123voygjQXSZXVrdqzLwwAxuGqtxym5lcAe7tRllmnXs/Nty/M5ICQhVU56pxoMvSjwwXySBdP69TC6YBNtLbDY9ySImd3lJpbJcc0ftuo2aU6FJjXMNFTuTjmVfw3g/fKvPcjVsTbHqVWOhyfI/smAJxgJx/ugEm9PFk7i2rIc3JkYtW1AyoIXGJBeytvZRlyDz9ulowYSEPCtKL6Z9tqMGPHUntKwwHKbRTBIGsDhnRLN095MYbb7d7aOagBIfOGSaxY3e/mpyXwQI="
109 changes: 58 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,35 @@ Microsoft TFS Python Library (TFS API Python client)

------

# Table of Contents
- [Introduction](#introduction)
- [Quickstart](#quickstart)
- [Installation](#installation)
- [Create connection](#create-connection)
- [Authorization](#authorization)
- [Timeout connection](#timeout-connection)
- [Workitem](#workitem)
- [Update workitem](#update-workitem)
- [Workitem attachments](#workitem-attachments)
- [Run Saved Queries](#run-saved-queries)
- [Run WIQL](#run-wiql)
- [Changesets](#changesets)
- [Project and Team](#project--team)
- [Advanced](#advanced)
- [Guide](#guide)
- [Compability](#compability)
- [Development](#development)
- [Tests](#tests)
- [TODO](#todo)
- [Compatibility](#Compatibility)
- [Contribute](#contribute)

------

# Introduction
Microsoft Team Foundation Server Python Library is a Microsoft TFS API Python client that can work with Microsoft TFS workflow and workitems.

This tool allows:
1. Get WorkItems (WI).
2. Set WI fields.
3. Run WI search queries.
4. Work with TFVC changesets.
5. Work with TFS Projects.
This python library allows:
1. Get [WorkItems (WI)](#workitem)
2. Set [WI fields](#update-workitem)
3. Run [WI search queries](#run-saved-queries)
4. Run [WIQL](#run-wiql)
4. Work [with TFVC changesets](docs/OTHER.md)
5. Work [with TFS Projects](docs/OTHER.md)

## Installation
```
Expand Down Expand Up @@ -90,14 +91,6 @@ print(workitem.field_names)
# Case insensetive. Remove space in field name
print(workitem['assignedTo'])

# Update field
workitem['state'] = 'Complete'

# Add comment
print(workitem.history)
workitem['History'] = "Omg, it is goos issue!"
print(workitem.history)

# Workitem Parent Workitem
parent = workitem.parent
if parent: # Parent is None if Workitem hasn't Parent link
Expand All @@ -107,6 +100,42 @@ if parent: # Parent is None if Workitem hasn't Parent link
childs = workitem.childs
if childs: # Child is empty list if Workitem hasn't Child link
print("Workitem with id={} have Childs={}".format(workitem.id, ",".join([x.id for x in childs])))

# Workitem revisions
revisions = workitem.revisions
```

### Update workitem

```python
# Update field
workitem['state'] = 'Complete'

# Add comment
print(workitem.history)
workitem['History'] = "Omg, it is goos issue!"
print(workitem.history)
```

### Workitem attachments
If workitem has attachments, you can download it and get info about.
```python
attachments = workitem.attachments
attachment = attachments[0]
# Internal TFS UID
print(attachment.id)

# Filename
print(attachment.name)

# TFS Download URL
print(attachment.url)

# You can download file to folder
attachment.download('/home/user/folder')

# All raw data
print(attachment.data)
```

## Run Saved Queries
Expand Down Expand Up @@ -159,39 +188,17 @@ workitems = wiql.workitems
print(workitems[0]['Title'])
```

## Changesets
```python
# Get changesets from 1000 to 1002
changesets = client.get_changesets(from_=1000, to_=1002)

# Get changesets and related Workitems
changesets = client.get_changesets(top=1)
linked_workitems = changesets[0].workitems
```

## Project & Team
```python
# Get all project
all_projects = client.get_projects()
## Advanced
- [Advanced usage](docs/ADVANCED.md)
- Some [others object available](docs/OTHERS.md)

# Get project
project_name = client.get_project("MyProjectName")
# Guide
If you use this library, [put a star](https://help.github.com/articles/about-stars/) on [this repository](https://github.com/devopshq/tfs). This motivates us and other developers to develop the library :)

# Get project team
project_team = project_name.team
```


## Guide
### Compability
## Compatibility
- Tested with **Python.3.4**
- TFS 2015
- TFS 2017

## Development
### Tests
We use HTTPPrety. For GET-response locate you response.json to folder by URL. E.g:
- http://tfs.tfs.ru/tfs/DefaultCollection/_apis/wit/workitems?ids=anyid&anyflag => **tests/resources/tfs/DefaultCollection/_apis/wit/workitems/response.json**
- http://tfs.tfs.ru/tfs/DefaultCollection/_apis/tfvc/changesets/10/workItems => **tests/resources/tfs/DefaultCollection/_apis/tfvc/changesets/10/workItems/response.json**

### TODO
- Implemented Resources-API (like https://github.com/pycontribs/jira)
## Contribute
[About contribute](docs/CONTRIBUTE.md)
80 changes: 80 additions & 0 deletions docs/ADVANCED.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Advanced usage
--------------

# Table of Contents
- [TFSObject](#tfsobject)
- [Workitem](#workitem)
- [Relations](#relations)
- [Links](#links)
- [TFSHTTPClient](#tfshttpclient)

# TFSObject
All `TFSObject` instances contain raw TFS response (in JSON, which was converted to python-dict) in `self.data`

```python
workitem = client.get_workitem(100)
print(workitem.data)

history = workitem.history
print(history.data)

revisions = workitem.revisions
print(revisions.data)

attachment = workitem.attachments[0]
print(attachment.data)
```

All `TFSObject` instances have `self.url`, `self.uri`:
```python
workitem = client.get_workitem(100)

# Full URL with https points to API object
print(workitem.url)

# URI points to API object
print(workitem.uri)

```

# Workitem

## Relations
Workitem has relation with other object. This library support only `workitem.childs`, `workitem.parent`, and `workitem.attachments`
Read more about [TFS link types](https://docs.microsoft.com/en-us/vsts/work/customize/reference/link-type-element-reference#link-types)

If you need find other type, you can use `workitem.find_in_relations` method:
```python
workitem = client.get_workitem(100)

# links is Dict
links = workitem.find_in_relations('Hyperlink')

# duplicates is Dict
# Really type is System.LinkTypes.Duplicate-Forward, but it will be found
duplicates = workitem.find_in_relations('Duplicate-Forward')
```

## Links
Some `TFSObject` have `_links` in their data. You can acces to this data as raw or get new `TFSObject`:
```python
workitem = client.get_workitem(100)

# This links also in dir()
dir(workitem)

# Get TFSObject
workitem.workItemHistory # list of object
workitem.workItemRevisions # list of object
workitem.workItemType # TFSObject

# Get raw data
links = workitem.data['_links']
print(links)

```

## TFSHTTPClient
**TODO**: Describe how other people can use some usefull function and object from `tfs.connection`
- Get from TFSAPI
- `send_*` methods
19 changes: 19 additions & 0 deletions docs/CONTRIBUTE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Table of Contents
- [Contribute](#contribute)
- [Development](#development)
- [Tests](#tests)

# Contribute
We will be grateful to see you in the ranks of the contributors! We have [some esay issue](https://github.com/devopshq/tfs/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22), which will suit as first issue or for junior python

## Development
Development takes place on GitHub, where the git-flow branch structure is used:

* ``master`` - contains the latest released code.
* ``develop`` - is used for development of the next release. **Pull request must be in this branch**
* ``feature/XXX`` - feature branches are used for development of new features before they are merged to ``develop``.

## Tests
We use HTTPPrety. For GET-response locate you response.json to folder by URL. E.g:
- http://tfs.tfs.ru/tfs/DefaultCollection/_apis/wit/workitems?ids=anyid&anyflag => **tests/resources/tfs/DefaultCollection/_apis/wit/workitems/response.json**
- http://tfs.tfs.ru/tfs/DefaultCollection/_apis/tfvc/changesets/10/workItems => **tests/resources/tfs/DefaultCollection/_apis/tfvc/changesets/10/workItems/response.json**
26 changes: 26 additions & 0 deletions docs/OTHERS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Table of Contents
- [Changesets](#changesets)
- [Project & Team](#project--team)


# Changesets
```python
# Get changesets from 1000 to 1002
changesets = client.get_changesets(from_=1000, to_=1002)

# Get changesets and related Workitems
changesets = client.get_changesets(top=1)
linked_workitems = changesets[0].workitems
```

# Project & Team
```python
# Get all project
all_projects = client.get_projects()

# Get project
project_name = client.get_project("MyProjectName")

# Get project team
project_team = project_name.team
```
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@

description='Microsoft TFS Python Library (TFS API Python client) that can work with TFS workflow and workitems.',

long_description='You can see detailed user manual here: https://devopshq.github.io/tfs/',
long_description='You can see detailed user manual here: https://github.com/devopshq/tfs/blob/master/README.md',

license='MIT',

author='Alexey Burov',

author_email='allburov@gmail.com',

url='https://devopshq.github.io/tfs/',
url='https://github.com/devopshq/tfs/blob/master/README.md',

download_url='https://github.com/devopshq/tfs.git',

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"id": "26e73aff-d80b-430d-b95c-76140bf184de",
"name": "ProjectName",
"url": "https:\/\/tfs.tfs.ru\/tfs\/DefaultCollection\/_apis\/projects\/26e73aff-d80b-430d-b95c-76140bf184de",
"url": "http:\/\/tfs.tfs.ru\/tfs\/DefaultCollection\/_apis\/projects\/26e73aff-d80b-430d-b95c-76140bf184de",
"state": "wellFormed",
"_links": {
"self": {
"href": "https:\/\/tfs.tfs.ru\/tfs\/DefaultCollection\/_apis\/projects\/26e73aff-d80b-430d-b95c-76140bf184de"
"href": "http:\/\/tfs.tfs.ru\/tfs\/DefaultCollection\/_apis\/projects\/26e73aff-d80b-430d-b95c-76140bf184de"
},
"collection": {
"href": "https:\/\/tfs.tfs.ru\/tfs\/_apis\/projectCollections\/9025d248-2b1b-48a7-bb43-8abf779eeeaa"
"href": "http:\/\/tfs.tfs.ru\/tfs\/_apis\/projectCollections\/9025d248-2b1b-48a7-bb43-8abf779eeeaa"
},
"web": {
"href": "https:\/\/tfs.tfs.ru\/tfs\/DefaultCollection\/ProjectName"
"href": "http:\/\/tfs.tfs.ru\/tfs\/DefaultCollection\/ProjectName"
}
},
"defaultTeam": {
"id": "6475f0ad-b08b-4a74-8576-d80baf80600a",
"name": "ProjectName Team",
"url": "https:\/\/tfs.tfs.ru\/tfs\/DefaultCollection\/_apis\/projects\/26e73aff-d80b-430d-b95c-76140bf184de\/teams\/6475f0ad-b08b-4a74-8576-d80baf80600a"
"url": "http:\/\/tfs.tfs.ru\/tfs\/DefaultCollection\/_apis\/projects\/26e73aff-d80b-430d-b95c-76140bf184de\/teams\/6475f0ad-b08b-4a74-8576-d80baf80600a"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"id": "26e73aff-d80b-430d-b95c-76140bf184de",
"name": "ProjectName",
"url": "https:\/\/tfs.tfs.ru\/tfs\/DefaultCollection\/_apis\/projects\/26e73aff-d80b-430d-b95c-76140bf184de",
"url": "http:\/\/tfs.tfs.ru\/tfs\/DefaultCollection\/_apis\/projects\/26e73aff-d80b-430d-b95c-76140bf184de",
"state": "wellFormed",
"revision": 43900539
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"id": "26e73aff-d80b-430d-b95c-76140bf184de",
"name": "ProjectName",
"url": "https:\/\/tfs.tfs.ru\/tfs\/DefaultCollection\/_apis\/projects\/26e73aff-d80b-430d-b95c-76140bf184de",
"url": "http:\/\/tfs.tfs.ru\/tfs\/DefaultCollection\/_apis\/projects\/26e73aff-d80b-430d-b95c-76140bf184de",
"state": "wellFormed",
"revision": 43900539
}
Expand Down
Loading

0 comments on commit ca03d8f

Please sign in to comment.