Skip to content

Instantly share code, notes, and snippets.

@arifb
Created April 4, 2024 18:26
Show Gist options
  • Save arifb/ff7c67cd054d3269aa227d5d4da4b3ed to your computer and use it in GitHub Desktop.
Save arifb/ff7c67cd054d3269aa227d5d4da4b3ed to your computer and use it in GitHub Desktop.
github issues export
require 'http'
require 'csv'
require 'json'
# Replace 'your_username' and 'your_repo' with your GitHub username and repository name
username = 'your_username'
repo = 'your_repo'
token = 'your_github_access_token' # Highly recommended for authenticated requests
# GitHub API URL for fetching issues from a repository
url = "https://api.github.com/repos/#{username}/#{repo}/issues"
# Perform the GET request to the GitHub API
response = HTTP.headers("Authorization" => "token #{token}").get(url)
# Parse the JSON response
issues = JSON.parse(response.body)
# Specify the path to your CSV file
csv_file = 'github_issues.csv'
# Open the CSV file for writing
CSV.open(csv_file, 'wb') do |csv|
# Define the column headers
csv << ['ID', 'Title', 'Body']
# Iterate over each issue and write its details to the CSV file
issues.each do |issue|
csv << [issue['number'], issue['title'], issue['body']]
end
end
puts "Export completed. Check the #{csv_file} file."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment