Skip to content

Commit

Permalink
feat: pull request assignee added done and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
skywarth committed Jul 1, 2024
1 parent 848b0ac commit d88cd17
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/ActionHandler/PullRequest/PullRequestAssigneeAddedStrategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import PullRequestStrategy, {OctokitResponsePullRequest} from "./PullRequestStrategy.js";
import {Emotion} from "../../enums/Emotion.js";
import {Sentiment} from "../../enums/Sentiment.js";
import {ActionContextDTO} from "../../DTO/ActionContextDTO.js";
import {EmitterWebhookEventName} from "@octokit/webhooks/dist-types/types";
import {CommentFactory} from "../../Comment/CommentFactory.js";
import Comment from "../../Comment/Comment.js";
import {CaseSlugs} from "../../enums/CaseSlug.js";


export default class PullRequestAssigneeAddedStrategy extends PullRequestStrategy<'pull_request.assigned'>{


protected getEventName(): EmitterWebhookEventName {
return "pull_request.assigned";
}


protected async executePrStrategy(commentFactory:CommentFactory,_previousPRs:Array<OctokitResponsePullRequest>): Promise<Comment|null> {


let tags: Array<string>=['assignment','team','support','backup','reinforce','reinforcement','aid','band','league','join','accompany','assemble','associate','enlist','guide','lead','pair','together','company','team up','stand together','unite','ally','suggest','request','plea','call','duty','demand','appeal','summon','invoke','invitation','invite','prayer','seek','hero','champion','evaluation','new','arrive','arrival','fresh','the one','savior','visitor','task','mission','goal'];
let contextEmotionMatrix: Emotion.EmotionMatrix=[
{emotion:Emotion.Interest.Trust,temperature:4},
{emotion:Emotion.Interest.Friendliness,temperature:5},
{emotion:Emotion.Fear.Fright,temperature:2},
{emotion:Emotion.Fear.Anxiety,temperature:1},
{emotion:Emotion.Joy.Relief,temperature:4},
{emotion:Emotion.Joy.Thrill,temperature:2},
{emotion:Emotion.Surprise.Amazement,temperature:2},
{emotion:Emotion.Surprise.Wonder,temperature:3},
];

let caseSlug: CaseSlugs.Types=CaseSlugs.PullRequest.Assignee.Added;
let sentiment :Sentiment=Sentiment.Positive;



const actionContext=new ActionContextDTO(contextEmotionMatrix,sentiment,tags);
const comment = commentFactory.create(caseSlug,actionContext);
return comment;

}

}
9 changes: 9 additions & 0 deletions src/enums/CaseSlug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export namespace CaseSlugs {

}

export const enum Assignee {
Added = "PullRequest.Assignee.Added",
Removed = "PullRequest.Assignee.Removed",

}

export namespace Review {
export const enum Submitted {
Approved = "PullRequest.Review.Submitted.Approved",
Expand Down Expand Up @@ -66,6 +72,9 @@ export namespace CaseSlugs {
| CaseSlugs.PullRequest.Reviewer.Added
| CaseSlugs.PullRequest.Reviewer.Removed

| CaseSlugs.PullRequest.Assignee.Added
| CaseSlugs.PullRequest.Assignee.Removed

| CaseSlugs.PullRequest.Review.Submitted.Approved
| CaseSlugs.PullRequest.Review.Submitted.ChangesRequested
| CaseSlugs.PullRequest.Review.Submitted.Commented
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PullRequestReviewSubmittedStrategy from "./ActionHandler/PullRequestRevie
import IssueCommentCreatedStrategy from "./ActionHandler/IssueComment/IssueCommentCreatedStrategy.js";
import PullRequestReviewerAdded from "./ActionHandler/PullRequest/PullRequestReviewerAdded.js";
import PullRequestReviewerRemoved from "./ActionHandler/PullRequest/PullRequestReviewerRemoved.js";
import PullRequestAssigneeAddedStrategy from "./ActionHandler/PullRequest/PullRequestAssigneeAddedStrategy.js";



Expand Down Expand Up @@ -40,4 +41,9 @@ export default (app: Probot) => {
return strat.handle();
});

app.on("pull_request.assigned", async (ghContext: Context<'pull_request.assigned'>) => {
const strat = new PullRequestAssigneeAddedStrategy(ghContext);
return strat.handle();
});

};
41 changes: 41 additions & 0 deletions test/feature/PullRequest/pullRequestAssigneeAdded.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {describe, test, afterEach, vi, beforeAll} from "vitest";
import {StrategyTestSetup} from "../strategyTestSetup";
import PullRequestAssigneeAddedStrategy from "../../../src/ActionHandler/PullRequest/PullRequestAssigneeAddedStrategy";


import prAssigneeAddedPayload from '../../fixtures/events/pull_request/assignee/pull_request.assignee.added.json';
import {CaseSlugs} from "../../../src/enums/CaseSlug";



describe("Pull Request assignee added tests", () => {
const strategyTestSetup = new StrategyTestSetup();


beforeAll(() => {
strategyTestSetup.beforeAll();
strategyTestSetup.actionStrategyHandleSpy = vi.spyOn(PullRequestAssigneeAddedStrategy.prototype as any, 'handle');
});

afterEach(() => {
strategyTestSetup.afterEach();
});


test("Creates comment", async () => {

const caseSlug=CaseSlugs.PullRequest.Assignee.Added;

await strategyTestSetup.probot.receive({
id: '123',
name: 'pull_request',
payload: prAssigneeAddedPayload as any,
});

strategyTestSetup.performCommonAssertions(caseSlug);

});



});
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"action": "assigned",
"pull_request": {
"id": 1,
"number": 555444,
"state": "open",
"title": "Test Pull Request",
"user": {
"login": "test-user",
"id": 101,
"avatar_url": "https://avatars.githubusercontent.com/u/101?v=4"
},
"head": {
"ref": "some-branch"
},
"base": {
"ref": "master"
},
"assignees": [
{
"login": "existing-user1",
"id": 102,
"avatar_url": "https://avatars.githubusercontent.com/u/102?v=4"
},
{
"login": "existing-user2",
"id": 103,
"avatar_url": "https://avatars.githubusercontent.com/u/103?v=4"
},
{
"login": "new-assigned-user",
"id": 104,
"avatar_url": "https://avatars.githubusercontent.com/u/104?v=4"
}
]
},
"repository": {
"id": 202,
"name": "test-repo",
"full_name": "test-owner/test-repo",
"owner": {
"login": "test-owner",
"id": 103,
"avatar_url": "https://avatars.githubusercontent.com/u/103?v=4"
}
},
"sender": {
"login": "test-user",
"id": 101,
"avatar_url": "https://avatars.githubusercontent.com/u/101?v=4"
},
"assignee": {
"login": "new-assigned-user",
"id": 104,
"avatar_url": "https://avatars.githubusercontent.com/u/104?v=4"
},
"installation": {
"id": 1
}
}

0 comments on commit d88cd17

Please sign in to comment.