Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functionality to support marking unreleased relaseses released #36

Open
trjate opened this issue Oct 21, 2020 · 3 comments
Open

Functionality to support marking unreleased relaseses released #36

trjate opened this issue Oct 21, 2020 · 3 comments

Comments

@trjate
Copy link

trjate commented Oct 21, 2020

I'm not sure if this functionality is already intended to be working or I'm misunderstanding the use of the -r, --released flag, but let's say I create a release via:

jira release -d "test 12" -p DEVOPS eid-releases-automator-v1.9.9

which I want to remain marked as "Unreleased" in JIRA.

Then some time later when that release has been deployed to Prod I want to mark it as "Released" in JIRA.

Should this work?

jira release -p DEVOPS -r "eid-releases-automator-v1.9.9"

When I execute the above it just prints the help menu:

Your first step is to run the config option.


  Usage: jira [options] [command]

  Commands:

    ls [options]           List my issues
....
....

Perhaps it's not intended to support updating the status of a release as released or unreleased after the initial release has been created?

Thanks!

@danshumaker
Copy link
Owner

Hi @tjterris ,
You are correct that is the intended usage. (confirmed by jira release -h) . I've tested this in the past and it works (worked).

By any chance did you try it without quotes? (spitballing here - because jira is very particular).
jira release -p DEVOPS -r eid-releases-automator-v1.9.9

Usually the way I get to the bottom of these issues is to output the actual API command to the console and then repeat the command in postman so I can parse through the very verbose error messages given back to us by the api.

Judging from ( https://docs.atlassian.com/software/jira/docs/api/REST/8.1.0/#api/2/version-createVersion ) which is a post command ( https://github.com/danshumaker/jira-cli/blob/master/lib/jira/release.js#L15 ), the update command ( https://docs.atlassian.com/software/jira/docs/api/REST/8.1.0/#api/2/version-updateVersion ) should be a put.

So we might need to change updates (how you are wanting to use it) to be put commands. sorry for any delays this might cause you waiting for a new version.

Feel free to submit patches or pull requests. Help is always welcome.

@trjate
Copy link
Author

trjate commented Oct 27, 2020

Hey @danshumaker Thanks so much for the reply. I tested it again with and without quotes and I wasn't able to be successful. I ended up rolling 2 functions myself to achieve the desired behavior. You're correct, a PUT command was required. I would be happy to contribute to your project since it's such a great tool, but unfortunately I'm incompetent with Javascript!

Here are the functions I ended up using, in Python.

JIRA_URL = "abcdefghij.atlassian.net"
JIRA_TOKEN = environ["JIRA_TOKEN"]
HEADER = {
    "Authorization": "Basic {}".format(JIRA_TOKEN),
    "Content-Type": "application/json",
}
PROJECT = environ.get("PROJECT")
RELEASE = environ.get("RELEASE")
...
...
...
def get_release_from_jira():
    """ Returns dict of desired release from JIRA """

    url = "https://{}/rest/api/2/project/{}/versions".format(JIRA_URL, PROJECT)
    response = requests.get(url, headers=HEADER)
    releases = json.loads(response.text)

    for release in releases:
        if release["name"] == RELEASE:
            return release


def mark_released(release):
    """ Takes release from previous function and PUTs a release status update to API """

    url = "https://{}/rest/api/2/version/{}".format(JIRA_URL, release["id"])
    release["released"] = True
    release["releaseDate"] = datetime.today().strftime("%Y-%m-%d")
    release.pop("userReleaseDate")
    release = json.dumps(release)
    response = requests.put(url, data=release, headers=HEADER)
    content = response.text
    logging.info(f"Release: {content}")

@danshumaker
Copy link
Owner

Man I love python.. Kudos @tjterris for rolling your own. Glad to know the put request worked. As soon as I resolve some merge conflicts+updates for another PR, I'll add put to the release update js command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants