Git Product home page Git Product logo

Comments (11)

hamelsmu avatar hamelsmu commented on July 22, 2024

BTW - Please feel free to tag me in issues from now on for some reason this didn't get on my radar. Looking into this now.

from ghapi.

hamelsmu avatar hamelsmu commented on July 22, 2024

Do you mind sharing the full code that created this error?

from ghapi.

choldgraf avatar choldgraf commented on July 22, 2024

Sure - though it is just the one-liner.

Given a card, for example this one:

https://github.com/orgs/jupyterhub/projects/1#card-15417167

with a card ID of 15417167

running this:

api.projects.move_card(15417167, 0)

results in HTTP422UnprocessableEntityError: HTTP Error 422: Unprocessable Entity

from ghapi.

choldgraf avatar choldgraf commented on July 22, 2024

friendly ping for @hamelsmu in case he isn't watching this repo :-)

from ghapi.

hamelsmu avatar hamelsmu commented on July 22, 2024

Sorry about that! Thanks for the reminder! This is currently on my backlog will try to get to this by next week hopefully

from ghapi.

choldgraf avatar choldgraf commented on July 22, 2024

No worries - in case this is helpful, I'd basically like to make this function work :-)

def sort_cards(column_id, labels, api):
    """Sort the cards in a GitHub Project column based on a list of labels.
    
    Note: cards that do not directly point to a GitHub issue will be treated
    like cards with issues that do not have one of the specified labels.
    
    Parameters
    ----------
    column_id: int
        The unique ID of the column you'd like to sort
    labels: list of strings
        A list of strings to use in sorting your cards. The cards will be sorted
        such that cards with first item of `labels` will come first.
    """
    if api is None:
        api = GhApi()
    cards = api.projects.list_cards(column['id'])
    for card in cards:
        # If the card points to an issue, grab its list of labels
        if "content_url" not in card:
            continue
        _, org, repo, _, num = card['content_url'].rsplit('/', 4)
        issue_labels = api.issues.list_labels_on_issue(org, repo, num)
        
        # Loop in reverse so that the first items in `labels` end up at the top
        for label in labels[::-1]:
            if any(label in ii['name'] for ii in issue_labels):
                api.projects.move_card(str(card['id']), 0)
                print(f"Moved card {card['id']}")

My use-case here is that I'd like to make it easier to "sort" the cards on a project board, based on the labels on issues they point to. The most obvious use for this is projects that have priority labels (so that priority:high would be at the top)

from ghapi.

hamelsmu avatar hamelsmu commented on July 22, 2024

from ghapi.

choldgraf avatar choldgraf commented on July 22, 2024

In case this helps debug: it also seems like this is the case for moving columns to other positions as well - so perhaps it has something to do with putting the right information in the body of the API call. E.g., the move_card API has this example:

curl \
  -X POST \
  -H "Accept: application/vnd.github.inertia-preview+json" \
  https://api.github.com/projects/columns/cards/42/moves \
  -d '{"position":"position"}'

And it sounds like the problem we're running into is in the generation of the -d '{"position":"position"}' part of the call.

from ghapi.

hamelsmu avatar hamelsmu commented on July 22, 2024

@choldgraf I've been pulled away for something at work that is going to be taking me away from open source for a couple of months :( Perhaps @jph00 can help here

from ghapi.

choldgraf avatar choldgraf commented on July 22, 2024

Ah bummer, I will try to figure something out 👍

from ghapi.

choldgraf avatar choldgraf commented on July 22, 2024

ah I think I finally figured this out. The problem is that the position key does not take a numerical argument (such as 0, 1, 2, etc). It takes a string like top or bottom. That's why it wasn't working.

This issue is resolved for me, and is really more of a GitHub Projects API documentation bug than here, so I'll close this

from ghapi.

Related Issues (20)

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.