Skip to content

Commit

Permalink
feat: create and list issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Kavitha Kesavalu authored and Kavitha Kesavalu committed Mar 17, 2024
1 parent 40752c1 commit f328e68
Show file tree
Hide file tree
Showing 17 changed files with 485 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module.exports = {
singleQuote: true,
trailingComma: 'es5',
printWidth: 100,
};
};
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ hooks:
post_checkout: npm install
apply: mv .eslintrc .eslintrc.json
pr_message: echo 'Hey! This PR renames `.eslintrc` to `.eslintrc.json`'
issues:
title: "this is my first updated issue"
description: "this is my first updated issue"
labels: ['ENHANCEMENT', 'BUG']
state: closed
state_reason: completed
```

### Fields
Expand Down Expand Up @@ -127,6 +133,16 @@ Hooks define the core functionality of a migration in Shepherd.
- **Description**: Commands to generate a pull request message.
- **Output**: Anything written to `stdout` is used for the message. Multiple commands will have their outputs concatenated.

- `issue`:
- **Description**: Command to create, update, or close issues.
- **Output**: Depending on the details provided in migration scripts, the issues will be created, updated or closed.

- `list-issues`:
- **Description**: Commands to list all issues associated with a migration.
- **Output**: All the posted issues are listed in the table format.



### Requirements

- Optional: `should_migrate`, `post_checkout`
Expand Down Expand Up @@ -167,6 +183,8 @@ There are a number of commands that must be run to execute a migration:
- `pr-preview`: Prints the commit message that would be used for each repository without actually creating a PR; uses the `pr_message` hook.
- `pr`: Creates a PR for each repo with the message generated from the `pr_message` hook.
- `version`: Prints Shepherd version
- `issue`: Create, update, or close issues across multiple repository.
- `list-issues`: List all issues associated with a migration.

By default, `checkout` will use the adapter to figure out which repositories to check out, and the remaining commands will operate on all checked-out repos. To only checkout a specific repo or to operate on only a subset of the checked-out repos, you can use the `--repos` flag, which specifies a comma-separated list of repos:

Expand Down
85 changes: 76 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@types/js-yaml": "^4.0.9",
"chalk": "^4.1.2",
"child-process-promise": "^2.2.1",
"table": "^6.8.1",
"commander": "^11.1.0",
"fs-extra": "^11.2.0",
"joi": "^17.11.0",
Expand Down
2 changes: 2 additions & 0 deletions src/adapters/adapter.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const mockAdapter: IRepoAdapter = {
getDataDir: jest.fn() as unknown as (repo: IRepo) => string,
getBaseBranch: jest.fn() as unknown as (repo: IRepo) => string,
getEnvironmentVariables: jest.fn() as unknown as (repo: IRepo) => Promise<IEnvironmentVariables>,
createIssue: jest.fn() as unknown as (repo: IRepo) => Promise<string>,
updateIssue: jest.fn() as unknown as (repo: IRepo) => Promise<void>,
};

export default mockAdapter;
8 changes: 8 additions & 0 deletions src/adapters/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ export interface IRepo {
[key: string]: any;
}

export interface IssueTracker {
[key: string]: any;
}

export interface IEnvironmentVariables {
[key: string]: string;
}
Expand Down Expand Up @@ -40,6 +44,10 @@ interface IRepoAdapter {
getBaseBranch(repo: IRepo): string;

getEnvironmentVariables(repo: IRepo): Promise<IEnvironmentVariables>;

createIssue(repo: IRepo): Promise<string>;

updateIssue(repo: IRepo, issueNumber: number): Promise<void>;
}

export default IRepoAdapter;
4 changes: 4 additions & 0 deletions src/adapters/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ abstract class GitAdapter implements IRepoAdapter {

protected abstract getRepositoryUrl(repo: IRepo): string;

public abstract createIssue(repo: IRepo): Promise<string>;

public abstract updateIssue(repo: IRepo, issueNumber: number): Promise<void>;

protected git(repo: IRepo): any {
return simpleGit(this.getRepoDir(repo));
}
Expand Down
37 changes: 37 additions & 0 deletions src/adapters/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,43 @@ class GithubAdapter extends GitAdapter {
return `git@${gitHubEnterpriseBaseUrl}:${repo.owner}/${repo.name}.git`;
}

public createIssue = async (repo: IRepo): Promise<string> => {
const {
migration: { spec },
} = this.migrationContext;
const { owner, name } = repo;
const { issues } = spec;
//Create an issue with the title , issue message and labels

return await this.githubService.createAndGetIssueNumber({
owner,
repo: name,
title: issues?.title || 0,
body: issues?.description,
labels: issues?.labels,
});
};

public updateIssue = async (repo: IRepo, issueNumber: number): Promise<void> => {
const {
migration: { spec },
} = this.migrationContext;
const { owner, name } = repo;
const { issues } = spec;

//Update an issue's title , issue message and labels
await this.githubService.updateIssue({
owner,
repo: name,
title: issues?.title?.toString(),
issue_number: issueNumber,
body: issues?.description,
labels: issues?.labels,
state: issues?.state,
state_reason: issues?.state_reason,
});
};

private async checkActionSafety(repo: IRepo): Promise<SafetyStatus> {
const { owner, name } = repo;

Expand Down
7 changes: 6 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import prStatus from './commands/pr-status';
import push from './commands/push';
import reset from './commands/reset';
import version from './commands/version';

import issue from './commands/issue';
import listIssues from './commands/list-issues';
import ConsoleLogger from './logger';

const program = new Command();
Expand Down Expand Up @@ -152,6 +153,10 @@ addCommand('pr-status', 'Check the status of all PRs for the specified migration
// These commands don't take --repos arguments
addCommand('list', 'List all checked out repositories for the given migration', false, list);

addCommand('issue', 'open an issue for the specified repos', true, issue);

addCommand('list-issues', 'List all opened issues using migration', true, listIssues);

program
.command('version')
.description('Print Shepherd version')
Expand Down
Loading

0 comments on commit f328e68

Please sign in to comment.