How can I export GitHub issues to Excel?

前端 未结 12 1834
逝去的感伤
逝去的感伤 2020-12-07 15:46

How can I export all my issues from an Enterprise GitHub repository to an Excel file? I have tried searching many Stack Overflow answers but did not succeed. I tried this so

相关标签:
12条回答
  • 2020-12-07 16:28

    I tried the methods described in other comments regarding exporting issues in JSON format. It worked ok but the formatting was somehow screwed up. Then I found in Excel help that it is able to access APIs directly and load the data from the JSON response neatly into my Excel sheets.

    The Google terms I used to find the help I needed were "excel power query web.content GET json". I found a How To Excel video which helped a lot.

    URL that worked in the Excel query (same as from other posts):

    https://api.github.com/repos/{owner}/{repo}/issues?page=1&per_page=100
    

    Personally, I also add the parameter &state=open, otherwise I need to request hundreds of pages. At one point I reached GitHub's limit on unauthenticated API calls/hour for my IP address.

    0 讨论(0)
  • 2020-12-07 16:30

    It is unfortunate that github.com does not make this easier.

    In the mean time, if you have jq and curl, you can do this in two lines using something like the following example that outputs issue number, title and labels (tags) and works for private repos as well (if you don't want to filter by label, just remove the labels={label}& part of the url). You'll need to substitute $owner, $repo, $label, and $username:

    # with personal access token = $PAT
    echo "number, title, labels" > issues.csv
    curl "https://api.github.com/repos/$owner/$repo/issues?labels=$label&page=1&per_page=100" -u "$username:$PAT" \
    | jq -r '.[] | [.number, .title, (.labels|map(.name)|join("/"))]|@csv' >> issues.csv
    
    # without PAT (will be prompted for password)
    echo "number, title, labels" > issues.csv
    curl "https://api.github.com/repos/$owner/$repo/issues?labels=$label&page=1&per_page=100" -u "$username" \
    | jq -r '.[] | [.number, .title, (.labels|map(.name)|join("/"))]|@csv' >> issues.csv
    

    Note that if your data exceeds 1 page, it may require additional calls.

    0 讨论(0)
  • 2020-12-07 16:32

    You can also try https://github.com/remoteorigin/git-issues-downloader but be sure to used the develop branch. The npm version and master branch is buggy.

    Or you can use this patched version with

    npm install -g https://github.com/mkobar/git-issues-downloader
    

    and then run with (for public repo)

    git-issues-downloader -n -p none -u none https://github.com/<user>/<repository>
    

    or for a private repo:

    git-issues-downloader -n -p <password or token> -u <user> https://github.com/<user>/<repository>
    

    Works great.

    0 讨论(0)
  • 2020-12-07 16:32

    GitHub's JSON API can be queried from directly in Excel using Power Query. It does require some knowledge about how to convert JSON into Excel table format but that's fairly Googlable.

    Here's how to first get to the data:

    • In Excel, on Ribbon, click Data > Get Data > From JSON. In dialog box, enter API URL ... in format similar to (add parms as you wish): https://api.github.com/repos/{owner}/{repo}/issues

    • A dialog box labeled "Access Web content" will appear.

    • On the left-hand side, click the Basic tab.

    • In the User name textbox, enter your GitHub username.

    • In the Password textbox, enter a GitHub password/Personal Access token.

    • Click Connect.

    • Power Query Editor will be displayed with a list of items that say Record.

    ... now Google around for how to transform accordingly so that the appropriate issue data can be displayed as a single table.

    0 讨论(0)
  • 2020-12-07 16:33

    Here is a tool that does it for you (uses the GitHub API): https://github.com/gavinr/github-csv-tools

    0 讨论(0)
  • 2020-12-07 16:34

    I have tinkered with this for quite some time and found that Power BI is a good way of keeping the data up to date in the spreadsheet. I had to look into Power BI a little to make this work, because getting the right info out of the structured JSON fields, and collapsing lists into concatenated strings, especially for labels, wasn't super intuitive. But this Power BI query works well for me by removing all the noise and getting relevant info into an easily digestible format that can be reviewed with stakeholders:

    let
        MyJsonRecord = Json.Document(Web.Contents("https://api.github.com/repos/<your org>/<your repo>/issues?&per_page=100&page=1&state=open&filter=all", [Headers=[Authorization="Basic <your auth token>", Accept="application/vnd.github.symmetra-preview+json"]])),
        MyJsonTable = Table.FromRecords(MyJsonRecord),
        #"Column selection" = Table.SelectColumns(MyJsonTable,{"number", "title", "user", "labels", "state", "assignee", "assignees", "comments", "created_at", "updated_at", "closed_at", "body"}),
        #"Expanded labels" = Table.ExpandListColumn(#"Column selection", "labels"),
        #"Expanded labels1" = Table.ExpandRecordColumn(#"Expanded labels", "labels", {"name"}, {"labels.name"}),
        #"Grouped Rows" = Table.Group(#"Expanded labels1", {"number","title", "user", "state", "assignee", "assignees", "comments", "created_at", "updated_at", "closed_at", "body"}, {{"Label", each Text.Combine([labels.name],","), type text}}),
        #"Removed Other Columns" = Table.SelectColumns(#"Grouped Rows",{"number", "title", "state", "assignee", "comments", "created_at", "updated_at", "closed_at", "body", "Label"}),
        #"Expanded assignee" = Table.ExpandRecordColumn(#"Removed Other Columns", "assignee", {"login"}, {"assignee.login"})
    in
        #"Expanded assignee"
    

    I added and then removed columns in this and did not clean this up - feel free to do that before you use it. Obviously, you also have to fill in your own organization name and repo name into the URL, and obtain the auth token. I have tested the URL with a Chrome REST plugin and got the token from entering the user and api key there. You can authenticate explicitly from Excel with the user and key if you don't want to deal with the token. I just find it simpler to go the anonymous route in the query setup and instead provide the readily formatted request header.

    Also, this works for repos with up to 100 open issues. If you have more, you need to duplicate the query (for page 2 etc) and combine the results.

    Steps for using this query:

    • in a new sheet, on the "Data" tab, open the "Get Data" drop-down
    • select "Launch Power Query Editor"
    • in the editor, choose "New Query", "Other Sources", "Blank query"
    • now you click on "Advanced Editor" and paste the above query
    • click the "Done" button on the Advanced Editor, then "Close and Load" from the tool bar
    • the issues are loading in your spreadsheet and you are in business
    • no crappy third-party tool needed
    0 讨论(0)
提交回复
热议问题