Skip to content

Commit

Permalink
feat(iam,gitcoin): query the cgrants API in the scorer by the github …
Browse files Browse the repository at this point in the history
  • Loading branch information
nutrina authored Aug 7, 2023
1 parent aed221a commit 901c868
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ jest.mock("axios");

const mockedAxios = axios as jest.Mocked<typeof axios>;
const userHandle = "my-login-handle";
const githubId = "18723656";
const clientId = process.env.GITHUB_CLIENT_ID;
const clientSecret = process.env.GITHUB_CLIENT_SECRET;
const cgrantsApiToken = process.env.CGRANTS_API_TOKEN;

const validGithubUserResponse = {
data: {
id: "18723656",
id: githubId,
login: userHandle,
type: "User",
},
Expand Down Expand Up @@ -136,7 +137,7 @@ describe("Attempt verification %s", function () {
});

// Check the request to get the contribution stats
expect(mockedAxios.get).toBeCalledWith(`${testUrl}?handle=${userHandle}`, {
expect(mockedAxios.get).toBeCalledWith(`${testUrl}?github_id=${githubId}`, {
headers: { Authorization: cgrantsApiToken },
});

Expand Down Expand Up @@ -417,7 +418,7 @@ describe("Attempt verification %s", function () {
expect(mockedAxios.get).toBeCalledWith("https://api.github.com/user", {
headers: { Authorization: `token ${githubAccessCode}` },
});
expect(mockedAxios.get).nthCalledWith(2, `${testUrl}?handle=user-handle-with-upper`, {
expect(mockedAxios.get).nthCalledWith(2, `${testUrl}?github_id=18723656`, {
headers: { Authorization: cgrantsApiToken },
});
expect(gitcoinPayload).toMatchObject({ valid: false });
Expand Down
7 changes: 3 additions & 4 deletions platforms/src/Gitcoin/Providers/gitcoinGrantsStatistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class GitcoinGrantStatisticsProvider implements Provider {
valid = !githubUser.errors && !!githubUser.id;
if (valid) {
const dataUrl = process.env.CGRANTS_API_URL + this.urlPath;
const gitcoinGrantsStatistic = await getGitcoinStatistics(dataUrl, githubUser.login, context);
const gitcoinGrantsStatistic = await getGitcoinStatistics(dataUrl, githubUser.id, context);

valid =
!gitcoinGrantsStatistic.errors &&
Expand Down Expand Up @@ -92,14 +92,13 @@ type GitcoinStatisticsContext = {

const getGitcoinStatistics = async (
dataUrl: string,
handle: string,
github_id: number,
context: GitcoinStatisticsContext
): Promise<GitcoinGrantStatistics> => {
if (!context.gitcoinGrantStatistics?.[dataUrl]) {
try {
// The gitcoin API expects lowercase handle
const lowerHandle = handle.toLowerCase();
const grantStatisticsRequest = await axios.get(`${dataUrl}?handle=${lowerHandle}`, {
const grantStatisticsRequest = await axios.get(`${dataUrl}?github_id=${github_id}`, {
headers: { Authorization: process.env.CGRANTS_API_TOKEN },
});

Expand Down

0 comments on commit 901c868

Please sign in to comment.