Skip to content

Commit

Permalink
refactor: restructure project by moving files to src directory and re…
Browse files Browse the repository at this point in the history
…moving unused JSON files
  • Loading branch information
0x4007 committed Oct 18, 2024
1 parent 37889f8 commit d2e9d73
Show file tree
Hide file tree
Showing 37 changed files with 76 additions and 181 deletions.
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

1 change: 0 additions & 1 deletion devpool-issues.json

This file was deleted.

1 change: 0 additions & 1 deletion devpool-statistics.json

This file was deleted.

8 changes: 4 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LABELS } from "./helpers/directory/directory";
import { ensureLabelExists } from "./helpers/directory/label-utils";
import { gitPush } from "./helpers/git";
import { main } from "./helpers/main";
import { LABELS } from "./src/directory/directory";
import { ensureLabelExists } from "./src/directory/label-utils";
import { gitPush } from "./src/git";
import { main } from "./src/main";

/**
* Main function
Expand Down
2 changes: 1 addition & 1 deletion mocks/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { http, HttpResponse } from "msw";
import { DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, GitHubIssue, GitHubLabel } from "../helpers/directory/directory";
import { DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, GitHubIssue, GitHubLabel } from "../src/directory/directory";
import { db } from "./db";
import issueDevpoolTemplate from "./issue-devpool-template.json";
import { default as issueTemplate, default as totalRewards } from "./issue-template.json";
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ts-template",
"name": "devpool-directory",
"version": "1.0.0",
"description": "Template repository with TypeScript support.",
"description": "Aggregates issues across our network.",
"main": "index.ts",
"author": "Ubiquity DAO",
"license": "MIT",
Expand Down
105 changes: 0 additions & 105 deletions scripts/delete-unauthorized-issues.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { commitTwitterMap } from "../git";
import { TwitterMap } from "../initialize-twitter-map";
import twitter from "../twitter";
import { TwitterMap } from "../twitter/initialize-twitter-map";
import twitter from "../twitter/twitter";
import { checkIfForked } from "./check-if-forked";
import { DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, GitHubIssue, GitHubLabel, LABELS, octokit } from "./directory";
import { getDirectoryIssueLabelsFromPartnerIssue } from "./get-directory-issue-labels";
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { GitHubIssue } from "./directory/directory";
import { getAllIssues } from "./directory/get-all-issues";
import { getIssueByLabel } from "./directory/get-issue-by-label";
import { getRepoCredentials } from "./directory/get-repo-credentials";
import { newDirectoryIssue } from "./directory/new-directory-issue";
import { syncIssueMetaData as syncDirectoryIssue } from "./directory/sync-issue-meta-data";
import { TwitterMap } from "./initialize-twitter-map";
import { TwitterMap } from "../twitter/initialize-twitter-map";
import { GitHubIssue } from "./directory";
import { getAllIssues } from "./get-all-issues";
import { getIssueByLabel } from "./get-issue-by-label";
import { getRepoCredentials } from "./get-repo-credentials";
import { newDirectoryIssue } from "./new-directory-issue";
import { syncIssueMetaData as syncDirectoryIssue } from "./sync-issue-meta-data";

export async function syncPartnerRepoIssues({
partnerRepoUrl,
Expand Down
4 changes: 2 additions & 2 deletions helpers/git.ts → src/git.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Statistics } from "../types/statistics";
import { DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, GitHubIssue, octokit } from "./directory/directory";
import { Statistics } from "./directory/statistics";
let gitChanges: Array<{ path: string; content: string }> = [];

async function gitCommit(data: unknown, fileName: string) {
Expand All @@ -15,7 +15,7 @@ async function gitCommit(data: unknown, fileName: string) {
}

import { Octokit } from "@octokit/rest";
import { TwitterMap } from "./initialize-twitter-map";
import { TwitterMap } from "./twitter/initialize-twitter-map";

const MAX_PAYLOAD_SIZE = 100000000; // 100MB per commit, adjust as needed

Expand Down
6 changes: 3 additions & 3 deletions helpers/main.ts → src/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Statistics } from "../types/statistics";
import { calculateStatistics } from "./directory/calculate-statistics";
import { DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, GitHubIssue } from "./directory/directory";
import { getAllIssues } from "./directory/get-all-issues";
import { getPartnerUrls as getPartnerRepoUrls } from "./directory/get-partner-urls";
import { Statistics } from "./directory/statistics";
import { syncPartnerRepoIssues } from "./directory/sync-partner-repo-issues";
import { commitStatistics, commitTasks } from "./git";
import { initializeTwitterMap, TwitterMap } from "./initialize-twitter-map";
import { syncPartnerRepoIssues } from "./sync-partner-repo-issues";
import { initializeTwitterMap, TwitterMap } from "./twitter/initialize-twitter-map";

export async function main() {
const twitterMap: TwitterMap = await initializeTwitterMap();
Expand Down
14 changes: 14 additions & 0 deletions src/twitter/delete-tweet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { twitterClient } from "./twitter";

export async function deleteTweet(id: string) {
try {
const { data } = await twitterClient.v2.deleteTweet(id);
if (data?.deleted) {
console.log(`Successfully deleted tweet, id: ${id}`);
} else {
console.log(`Could not delete tweet, id ${id}`);
}
} catch (error) {
console.error("Error deleting tweet", error);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFile } from "fs/promises";
import { commitTwitterMap } from "./git";
import { commitTwitterMap } from "../git";

export type TwitterMap = Record<string, string>;

Expand Down
11 changes: 11 additions & 0 deletions src/twitter/post-tweet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { twitterClient } from "./twitter";

export async function postTweet(status: string) {
try {
const { data } = await twitterClient.v2.tweet(status);
console.log(`Tweet posted successfully, id: ${data.id}, text: ${data.text}`);
return data;
} catch (error) {
console.error("Error posting tweet", error);
}
}
29 changes: 4 additions & 25 deletions helpers/twitter.ts → src/twitter/twitter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { TwitterApi } from "twitter-api-v2";
import dotenv from "dotenv";
import { TwitterApi } from "twitter-api-v2";
import { deleteTweet } from "./delete-tweet";
import { postTweet } from "./post-tweet";
dotenv.config();

// Check for each environment variable
Expand All @@ -12,7 +14,7 @@ if (!apiKey || !apiKeySecret || !accessToken || !accessTokenSecret) {
throw new Error("Twitter environment variables are not set");
}

const twitterClient = new TwitterApi({
export const twitterClient = new TwitterApi({
appKey: apiKey,
appSecret: apiKeySecret,
accessToken: accessToken,
Expand All @@ -24,26 +26,3 @@ export default {
deleteTweet,
client: twitterClient,
};

async function postTweet(status: string) {
try {
const { data } = await twitterClient.v2.tweet(status);
console.log(`Tweet posted successfully, id: ${data.id}, text: ${data.text}`);
return data;
} catch (error) {
console.error("Error posting tweet", error);
}
}

async function deleteTweet(id: string) {
try {
const { data } = await twitterClient.v2.deleteTweet(id);
if (data?.deleted) {
console.log(`Successfully deleted tweet, id: ${id}`);
} else {
console.log(`Could not delete tweet, id ${id}`);
}
} catch (error) {
console.error("Error deleting tweet", error);
}
}
14 changes: 7 additions & 7 deletions tests/devpool-issue-handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { drop } from "@mswjs/data";
import { setupServer } from "msw/node";
import { calculateStatistics } from "../helpers/directory/calculate-statistics";
import { checkIfForked } from "../helpers/directory/check-if-forked";
import { GitHubIssue } from "../helpers/directory/directory";
import { getPartnerUrls } from "../helpers/directory/get-partner-urls";
import { getRepoUrls } from "../helpers/directory/get-repo-urls";
import { newDirectoryIssue } from "../helpers/directory/new-directory-issue";
import { syncIssueMetaData } from "../helpers/directory/sync-issue-meta-data";
import { db } from "../mocks/db";
import { handlers } from "../mocks/handlers";
import issueDevpoolTemplate from "../mocks/issue-devpool-template.json";
import issueTemplate from "../mocks/issue-template.json";
import { calculateStatistics } from "../src/directory/calculate-statistics";
import { checkIfForked } from "../src/directory/check-if-forked";
import { GitHubIssue } from "../src/directory/directory";
import { getPartnerUrls } from "../src/directory/get-partner-urls";
import { getRepoUrls } from "../src/directory/get-repo-urls";
import { newDirectoryIssue } from "../src/directory/new-directory-issue";
import { syncIssueMetaData } from "../src/directory/sync-issue-meta-data";

const DEVPOOL_OWNER_NAME = "ubiquity";
const DEVPOOL_REPO_NAME = "devpool-directory";
Expand Down
18 changes: 9 additions & 9 deletions tests/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { describe, test } from "@jest/globals";
import { drop } from "@mswjs/data";
import { DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, GitHubIssue } from "../helpers/directory/directory";
import { getAllIssues } from "../helpers/directory/get-all-issues";
import { getDirectoryIssueLabelsFromPartnerIssue } from "../helpers/directory/get-directory-issue-labels";
import { getIssueByLabel } from "../helpers/directory/get-issue-by-label";
import { getIssueLabelValue } from "../helpers/directory/get-issue-label-value";
import { getIssuePriceLabel } from "../helpers/directory/get-issue-price-label";
import { getRepoCredentials } from "../helpers/directory/get-repo-credentials";
import { getRepoUrls } from "../helpers/directory/get-repo-urls";
import { getSocialMediaText } from "../helpers/directory/get-social-media-text";
import { db } from "../mocks/db";
import cfg from "../mocks/issue-devpool-template.json";
import { server } from "../mocks/node";
import { DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, GitHubIssue } from "../src/directory/directory";
import { getAllIssues } from "../src/directory/get-all-issues";
import { getDirectoryIssueLabelsFromPartnerIssue } from "../src/directory/get-directory-issue-labels";
import { getIssueByLabel } from "../src/directory/get-issue-by-label";
import { getIssueLabelValue } from "../src/directory/get-issue-label-value";
import { getIssuePriceLabel } from "../src/directory/get-issue-price-label";
import { getRepoCredentials } from "../src/directory/get-repo-credentials";
import { getRepoUrls } from "../src/directory/get-repo-urls";
import { getSocialMediaText } from "../src/directory/get-social-media-text";

beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
Expand Down
Loading

1 comment on commit d2e9d73

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 84%
84.09% (37/44) 73.33% (11/15) 100% (3/3)

JUnit

Tests Skipped Failures Errors Time
8 0 💤 2 ❌ 0 🔥 7.956s ⏱️

Please sign in to comment.