Skip to content

Instantly share code, notes, and snippets.

@gaelreyrol
Created July 15, 2021 16:26
Show Gist options
  • Save gaelreyrol/5deead78472746cba93730d8f14f719c to your computer and use it in GitHub Desktop.
Save gaelreyrol/5deead78472746cba93730d8f14f719c to your computer and use it in GitHub Desktop.
Copy Github cards to another project

Copy Github cards to another project

Usage

  • Create an access token with permission on projects.
  • Install with npm @octokit/core and dotenv.
  • Create a .env file with ACCESS_TOKEN=mytoken
  • Copy/paste this script in an index.js file.
  • Get column ids for source and destination.

Add the following line:

copy('mysourcecolumn', 'mydestinationcolumn');

Run your index.js file!

const { Octokit } = require('@octokit/core');
const dotenv = require('dotenv')
dotenv.config()
const octokit = new Octokit({
auth: process.env.ACCESS_TOKEN,
});
async function getCards(column) {
const { data } = await octokit.request('GET /projects/columns/{column_id}/cards', {
column_id: column,
per_page: 100,
mediaType: {
previews: [
'inertia'
]
}
});
return data;
};
async function createCard({ column, note }) {
const { data } = await octokit.request('POST /projects/columns/{column_id}/cards', {
column_id: column,
note,
mediaType: {
previews: [
'inertia'
]
}
});
return data;
}
async function copy(sourceColumn, destinationColumn) {
const cards = await getCards(sourceColumn);
cards
.map((card) => createCard({
column: destinationColumn,
note: card.note
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment