Skip to content

Add support for Bitbucket migration #2

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"axios": "^1.6.0",
"mime-types": "^2.1.34",
"readline-sync": "^1.4.10",
"ts-node": "^10.4.0"
"ts-node": "^10.4.0",
"bitbucket-api-v2": "^0.8.0" // Added dependency for interacting with Bitbucket's API
},
"devDependencies": {
"@types/mime-types": "^2.1.1",
Expand Down
47 changes: 47 additions & 0 deletions src/bitbucketHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import axios from 'axios';

export class BitbucketHelper {
bitbucketApiBaseUrl: string;
bitbucketToken: string;

constructor(bitbucketToken: string) {
this.bitbucketApiBaseUrl = 'https://api.bitbucket.org/2.0';
this.bitbucketToken = bitbucketToken;
}

async fetchRepositories(workspace: string) {
const url = `${this.bitbucketApiBaseUrl}/repositories/${workspace}`;
const headers = { Authorization: `Bearer ${this.bitbucketToken}` };
try {
const response = await axios.get(url, { headers });
return response.data.values;
} catch (error) {
console.error('Error fetching Bitbucket repositories:', error);
throw error;
}
}

async fetchIssues(repoSlug: string, workspace: string) {
const url = `${this.bitbucketApiBaseUrl}/repositories/${workspace}/${repoSlug}/issues`;
const headers = { Authorization: `Bearer ${this.bitbucketToken}` };
try {
const response = await axios.get(url, { headers });
return response.data.values;
} catch (error) {
console.error('Error fetching Bitbucket issues:', error);
throw error;
}
}

async fetchPullRequests(repoSlug: string, workspace: string) {
const url = `${this.bitbucketApiBaseUrl}/repositories/${workspace}/${repoSlug}/pullrequests`;
const headers = { Authorization: `Bearer ${this.bitbucketToken}` };
try {
const response = await axios.get(url, { headers });
return response.data.values;
} catch (error) {
console.error('Error fetching Bitbucket pull requests:', error);
throw error;
}
}
}
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SimpleMilestone,
} from './githubHelper';
import { GitlabHelper, GitLabIssue, GitLabMilestone } from './gitlabHelper';
import { BitbucketHelper } from './bitbucketHelper';
import settings from '../settings';

import { Octokit as GitHubApi } from '@octokit/rest';
Expand Down Expand Up @@ -94,9 +95,12 @@ const githubHelper = new GithubHelper(
settings.useIssuesForAllMergeRequests
);

// Bitbucket migration integration
const bitbucketHelper = settings.bitbucket ? new BitbucketHelper(settings.bitbucket.token) : null;

// If no project id is given in settings.js, just return
// all of the projects that this user is associated with.
if (!settings.gitlab.projectId) {
if (!settings.gitlab.projectId && !settings.bitbucket) { // Check for Bitbucket settings
gitlabHelper.listProjects();
} else {
// user has chosen a project
Expand Down
7 changes: 7 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default interface Settings {
dryRun: boolean;
gitlab: GitlabSettings;
github: GithubSettings;
bitbucket?: BitbucketSettings; // Added Bitbucket settings
usermap: {
[key: string]: string;
};
Expand Down Expand Up @@ -56,6 +57,12 @@ export interface GitlabSettings {
sessionCookie: string;
}

export interface BitbucketSettings { // Added Bitbucket settings interface
token: string;
workspace: string;
repoSlug: string;
}

export interface S3Settings {
accessKeyId: string;
secretAccessKey: string;
Expand Down