Skip to content
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
25 changes: 19 additions & 6 deletions github/handlers/EventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from "../helpers/githubSDK";
import { sendNotification } from "../lib/message";
import { subscriptionsModal } from "../modals/subscriptionsModal";
import { getGithubOauthBlock } from "../oath2/authentication";
import { getAccessTokenForUser } from "../persistance/auth";
import { Subscription } from "../persistance/subscriptions";
import { HandleInvalidRepoName } from "./HandleInvalidRepoName";
Expand Down Expand Up @@ -135,12 +136,16 @@ export async function SubscribeAllEvents(
console.log("SubcommandError", error);
}
} else {
const user = context.getSender();
const message = `Login to subscribe to repository events!`;
const block = await getGithubOauthBlock(app, user, modify, message);
await sendNotification(
read,
modify,
context.getSender(),
user,
room,
"Login to subscribe to repository events ! `/github login`"
message,
block
);
}
}
Expand Down Expand Up @@ -254,12 +259,16 @@ export async function UnsubscribeAllEvents(
console.log("SubcommandError", error);
}
} else {
const user = context.getSender();
const message = `Login to unsubscribe from repository events!`;
const block = await getGithubOauthBlock(app, user, modify, message);
await sendNotification(
read,
modify,
context.getSender(),
user,
room,
"Login to subscribe to repository events ! `/github login`"
message,
block
);
}
}
Expand Down Expand Up @@ -295,12 +304,16 @@ export async function ManageSubscriptions(
console.log("Invalid Trigger ID !");
}
} else {
const user = context.getSender();
const message = `Login to manage repository events!`;
const block = await getGithubOauthBlock(app, user, modify, message);
await sendNotification(
read,
modify,
context.getSender(),
user,
room,
"Login to subscribe to repository events ! `/github login`"
message,
block
);
}
}
10 changes: 8 additions & 2 deletions github/handlers/HandleIssues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { sendNotification } from "../lib/message";
import { NewIssueStarterModal } from "../modals/newIssueStarterModal";
import { getAccessTokenForUser } from "../persistance/auth";
import { GitHubIssuesStarterModal } from "../modals/getIssuesStarterModal";
import { getGithubOauthBlock } from "../oath2/authentication";
import { createSectionBlock } from "../lib/blocks";

export async function handleNewIssue(
read: IRead,
Expand Down Expand Up @@ -42,12 +44,16 @@ export async function handleNewIssue(
console.log("invalid Trigger ID !");
}
} else {
const user = context.getSender();
const message = `Login to add a new issue!`;
const block = await getGithubOauthBlock(app, user, modify, message);
await sendNotification(
read,
modify,
context.getSender(),
user,
room,
"Login to subscribe to repository events ! `/github login`"
message,
block
);
}
}
Expand Down
9 changes: 7 additions & 2 deletions github/handlers/SearchHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco
import { GithubApp } from "../GithubApp";
import { sendNotification } from "../lib/message";
import { githubSearchModal } from "../modals/githubSearchModal";
import { getGithubOauthBlock } from "../oath2/authentication";
import { getAccessTokenForUser } from "../persistance/auth";

export async function handleSearch(
Expand Down Expand Up @@ -41,12 +42,16 @@ export async function handleSearch(
console.log("invalid Trigger ID !");
}
} else {
const user = context.getSender();
const message = `Login to search issues!`;
const block = await getGithubOauthBlock(app, user, modify, message);
await sendNotification(
read,
modify,
context.getSender(),
user,
room,
"Login to subscribe to repository events ! `/github login`"
message,
block
);
}
}
10 changes: 8 additions & 2 deletions github/handlers/UserProfileHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { IRoom } from "@rocket.chat/apps-engine/definition/rooms";
import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands";
import { UIKitInteractionContext } from "@rocket.chat/apps-engine/definition/uikit";
import { GithubApp } from "../GithubApp";
import { createSectionBlock } from "../lib/blocks";
import { sendNotification } from "../lib/message";
import { userProfileModal } from "../modals/UserProfileModal";
import { getGithubOauthBlock } from "../oath2/authentication";
import { getAccessTokenForUser } from "../persistance/auth";

export async function handleUserProfileRequest(
Expand Down Expand Up @@ -40,12 +42,16 @@ export async function handleUserProfileRequest(
);
}
}else {
const user = context.getSender();
const message = `Login to get your user info!`;
const block = await getGithubOauthBlock(app, user, modify, message);
await sendNotification(
read,
modify,
context.getSender(),
user,
room,
"Login is Mandatory for getting User Info ! `/github login`"
message,
block
)
}

Expand Down
14 changes: 10 additions & 4 deletions github/oath2/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ export async function authorize(
room: IRoom,
persistence: IPersistence
): Promise<void> {
const message = `Login to GitHub`;
const block = await getGithubOauthBlock(app, user, modify, message);
await storeInteractionRoomData(persistence,user.id,room.id);
await sendNotification(read, modify, user, room, message, block);
}

export async function getGithubOauthBlock(app: GithubApp, user: IUser, modify: IModify, message: string) {
const url = await app
.getOauth2ClientInstance()
.getUserAuthorizationUrl(user);
Expand All @@ -26,8 +33,7 @@ export async function authorize(
text: "GitHub Login",
url: url.toString(),
};
const message = `Login to GitHub`;

const block = await createSectionBlock(modify, message, button);
await storeInteractionRoomData(persistence,user.id,room.id);
await sendNotification(read, modify, user, room, message, block);
}
return block;
}