Code Monkey home page Code Monkey logo

helix-swarm's Introduction

Hi, I am a software engineer, curious about all computer science, especially backend, services,
and system programming.

More than 10 years of commercial experience, last time working mostly as full stack, use Python,
love Django, know JS, have a background with system programming, reverse engineering.

Regularly participate in leetcode contests, have a few public Python packages on PyPI.

Addicted to GitHub, LeetCode & Continuous Improvement โœŒ๏ธ

https://linkedin.com/in/pbelskiy
https://leetcode.com/pbelskiy
https://medium.com/@pbelskiy

helix-swarm's People

Contributors

pbelskiy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

helix-swarm's Issues

Unable to query with array/list parameters (like multiple authors)

Use Case
I'd like to get reviews, constrained by a list of authors: Joe and Betty.

AUTHORS = ['joe', 'betty']
client = SwarmClient(API_SERVER, user=creds[0], password=creds[1])
reviews = client.reviews.get(authors=AUTHORS)

Observation
Lets say I know that Joe has 6 reviews, Betty has 4, for a total of 10. The URI that gets created looks like the following:
api/v9/reviews?author=joe&author=betty

However, what ends up happening, is that I ONLY get the 4 reviews for Betty. I get no reviews for Joe.

Expected Behavior
I should get all 10 reviews back - the 6 from Joe, and the 4 from Betty. The query URI should be formatted as follows:
api/v9/reviews?author[]=joe&author[]=betty
or more specifically:
api/v9/reviews?author%5B%5D=joe&author%5B%5D=betty

This seems to be the case with any URI parameter that can accept multiple entries. Locally, to test this, I made the following change:

# endpoints/reviews.py - get() around line 115
# NOTE - the addition of the square brackets after the author
...
        if authors:
            params['author[]'] = authors
            if float(self.swarm.version) < 2:
                raise SwarmCompatibleError(
                    'author field is supported from API version >= 2'
                )
...

With this change, the URI is formatted appropriately, the params are properly processed by the underlying requests module, and the query succeeds as expected.

I have not had the opportunity to dig in and explore the full codebase to root out every instance where this should be supported, so unfortunately, I do not have a PR for you at this time.

todo for 0.8.0

  • move endpoints from swarm to core.py endpoint?
  • rename SwarmAsyncClient to AsyncSwarmClient
  • rename helix-swarm to helixswarm (or alias in PyPI)

Creating review does not add multiple reviewers, any required reviewers

Here I am trying to create a review with 2 required reviewers

required=['bob', 'charlie']
review = client.reviews.create(
  change,
  reviewers=required,
  required_reviewers=required
)
pprint(review)

This is giving me:

{'review': {'approvals': None,
            'author': 'alice',
            'changes': [1234567],
            'commitStatus': [],
            'commits': [],
            'created': 1629563212,
            'deployDetails': [],
            'deployStatus': None,
            'description': 'Testing Swarm API\n',
            'groups': [],
            'id': 45678,
            'participants': {'alice': [], 'charlie': []},
            'pending': True,
            'projects': [],
            'reviewerGroups': [],
            'state': 'needsReview',
            'stateLabel': 'Needs Review',
            'testDetails': [],
            'testStatus': None,
            'type': 'default',
            'updated': 1629563212,
            'versions': []}}

Essentially, only the last person in required is being added as a reviewer, and they are not marked as a required reviewer in the created review.

I turned on logging in the requests library so I could inspect the POST:

send: b'POST /api/v9/reviews HTTP/1.1\r\nHost: swarm.domain.com\r\nUser-Agent: python-requests/2.26.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-Length: 102\r\nContent-Type: application/x-www-form-urlencoded\r\nAuthorization: Basic <omitted>\r\n\r\n'
send: b'change=1234567&reviewers=bob&reviewers=charlie&requiredReviewers=bob&requiredReviewers=charlie'
reply: 'HTTP/1.1 200 OK\r\n'

The parameters don't look right for an "array of strings" as described in the Swarm API docs.

change=1234567&reviewers=bob&reviewers=charlie&requiredReviewers=bob&requiredReviewers=charlie

Doing some digging, this line is doing using the data argument to requests.request instead of json.

return self.swarm._request('POST', 'reviews', data=data)

See this Stack Overflow question for why json should be used instead of data when you are sending an array in your POST.


Information about my environment:

  • Python 3.6.2 (yeah, I know... ๐Ÿคฃ)
  • helix-swarm version 0.6.2
>>> print(client.get_version())
{'apiVersions': [1, 1.1, 1.2, 2, 3, 4, 5, 6, 7, 8, 9, 10], 'version': 'SWARM/2020.1/1999242 (2020/08/20)', 'year': '2020'}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.