Skip to content

Add a script to send GH payloads #4

Open

Description

@ezio-melotti

In order to test GH integration, there should be a script able to send requests like the ones sent by GH when a PR is created or modified or when a PR/commit message mentions bpo-NNNNN.

The script should be able to:

  1. read and send payloads from a file
  2. generate payloads of the given type, with the values provided or with default values.

This script might also be exploited by the tests.

Activity

  1. AnishShah commented on Mar 28, 2017

    @AnishShah
    Contributor

    Hi, I want work on this.
    Should it be a python script right?
    And can you explain the second point? What do you mean by the given type, with the values provided or with default values.

  2. ezio-melotti commented on Mar 28, 2017

    @ezio-melotti
    MemberAuthor

    Hi,
    I already started working on it a while ago, and the script is now able to send payload from files, but I still have to clean it up a bit and submit a PR.

    Once I do (hopefully later today) that you are welcome to work on the second point.

    The API should be something similar:

    ghsend.py --type pull_request
    ghsend.py --type pull_request --action reopened
    ghsend.py --type push --author ezio.melotti --title 'bpo-12345: fix a bug'
    

    You should be familiar with the several available fields (https://developer.github.com/webhooks/), the ones we use most frequently, and what the best default for each is. For example the default type could be pull_request, and the default action could be opened, but it should be possible to specify other values if I want to. Feel free to ask if you have any other questions.

  3. AnishShah commented on Mar 28, 2017

    @AnishShah
    Contributor
  4. added a commit that references this issue on Mar 29, 2017
  5. ezio-melotti commented on Mar 29, 2017

    @ezio-melotti
    MemberAuthor

    I created a pull request with the initial version of the script.
    I designed it in such a way that it should be easy to extend and implement the second point:

    1. define a file/constant with one or more basic payloads (if different types have different structures)
    2. update parse_args() to accept and parse additional arguments (e.g. author, title, prnum, etc.)
    3. update the basic payload with the specified arguments (add a separate function)
    4. update the DEFAULT_HEADERS with the type of event (e.g. headers['X-GitHub-Event'] = 'pull_request')
    5. call send_request(payload, headers) -- the function will take care of calculating the signature and adding headers for it and for the content-length.

    A couple of notes about the current version:

    • If the argument is a filename with no path (e.g. python3 image/bin/ghsend.py pullrequestevent.txt, the script will look for it in ../roundup/test/data, if it's a path (relative or absolute), it will follow the path.
    • I created this file in image/bin/ because I thought of using it from within the docker, but later realized it's easier to use it from outside the docker. I currently keep docker running in one terminal tab with roundup running, and I execute the script from a separate tab outside docker (on docker-b.p.o/). This is also why I decided to set the default path to ../roundup/test/data rather than /opt/tracker/roundup/test/data. It's probably possible to connect two shell to the docker and run roundup in one and ghsend in the other, but I don't see any advantage in doing so.
  6. AnishShah commented on Mar 30, 2017

    @AnishShah
    Contributor

    Thanks @ezio-melotti! I got it.
    Should I fork your repo and send a PR to your branch and then include it in this PR #12? or should I wait till this gets in?

  7. added a commit that references this issue on Mar 30, 2017
  8. ezio-melotti commented on Mar 30, 2017

    @ezio-melotti
    MemberAuthor

    I went ahead and merged it so you can start working on it, @soltysh can look at it once he has time.

  9. AnishShah commented on Apr 3, 2017

    @AnishShah
    Contributor

    Should the payload have all the key/value pair or just few of those that are important for roundup?

  10. ezio-melotti commented on Apr 3, 2017

    @ezio-melotti
    MemberAuthor

    In theory it would be good to create requests that are as close to the original as possible, but you could also remove some items if they are not important for Roundup and if it makes the script simpler.
    Is there any specific problem you are trying to solve?

  11. AnishShah commented on Apr 3, 2017

    @AnishShah
    Contributor

    So currently we are using Push, IssueComment and PullRequest events. The payload is quite different for all these events. I was thinking of creating a sample file for each event and then according to the arguments change the key/values (like title, author, etc).

  12. ezio-melotti commented on Apr 3, 2017

    @ezio-melotti
    MemberAuthor

    SGTM.

  13. AnishShah commented on Apr 3, 2017

    @AnishShah
    Contributor
  14. ezio-melotti commented on Apr 4, 2017

    @ezio-melotti
    MemberAuthor

    Once we can use the script to create requests, it would also be nice to have an option to send them (headers + payload) to stdout or to a file. This will be convenient for creating test file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions