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

Add support for draft and prerelease #1

Merged
merged 4 commits into from
May 19, 2018
Merged

Conversation

kspearrin
Copy link
Contributor

@kspearrin kspearrin commented May 19, 2018

I need to create all of my GH releases from CI as drafts. Draft and prerelease options we missing. This PR adds them.

Additionally, draft releases are not returned by the getReleaseByTag API so I ported the function over to use getReleases with a filter instead.

Copy link
Owner

@cheton cheton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getReleases api will return only 30 results (max 100) per page. You have to iterate all pages to fetch all results.

https://octokit.github.io/rest.js/#api-Repos-getReleases

@cheton
Copy link
Owner

cheton commented May 19, 2018

You can refer to below code to fetch all results.

(async () => {
    const { owner, repo, tag, name, body } = program;

    try {
        let page = 1;
        let lastPage = 1;

        do {
            const releases = await getReleases({
                owner: owner,
                repo: repo,
                page: page,
                per_page: 30
            });

            console.log(`Fetched ${releases.length} results at page ${page}.`);

            const pagination = (releases.meta.link || '').split(',')
                .reduce((acc, link) => {
                    const r = link.match(/\?page=(\d)+.*rel="(\w+)"/);
                    if (r && r[1] && r[2]) {
                        const key = r[2];
                        const value = Number(r[1]) || 0;
                        acc[key] = value;
                    }
                    return acc;
                }, {});

            if (pagination.last > 0) {
                lastPage = pagination.last;
            }

            ++page;
        } while (page <= lastPage);
    } catch (err) {
        // Ignore error
    }
})();

@kspearrin
Copy link
Contributor Author

Thanks for the code. I added it in.

@cheton
Copy link
Owner

cheton commented May 19, 2018

It looks great. Thank you for your contribution.

@cheton cheton merged commit b9f560a into cheton:master May 19, 2018
@kspearrin
Copy link
Contributor Author

Great. Any chance of a release anytime soon so I can use it? :)

@cheton
Copy link
Owner

cheton commented May 19, 2018

Published v0.4.0
https://www.npmjs.com/package/github-release-cli

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

Successfully merging this pull request may close these issues.

None yet

2 participants