Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf8cc23e

Browse files
committed
add getPinnedPosts & public-types
1 parent023bd1b commitf8cc23e

File tree

8 files changed

+168
-7
lines changed

8 files changed

+168
-7
lines changed

‎e2e/getPinnedPosts.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import{GithubBlog}from"../dist/github-blog";
2+
3+
constblog=newGithubBlog({
4+
repo:"renatorib/github-blog-tests",
5+
token:process.env.GITHUB_E2E_TESTS_TOKEN!,
6+
});
7+
8+
describe("getPinnedPosts",()=>{
9+
test("get pinned posts",async()=>{
10+
constresult=awaitblog.getPinnedPosts();
11+
12+
expect(result.pinnedPosts.length).toBe(1);
13+
expect(result.pinnedPosts[0].pinnedBy.login).toBe("renatorib");
14+
expect(result.pinnedPosts[0].post.title).toBe("Pinned post");
15+
});
16+
});

‎package.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
"dev":"yarn codegen --watch",
1515
"prebuild":"yarn codegen",
1616
"build":"yarn clean && tsc",
17-
"pree2e-tests":"yarn build",
18-
"e2e-tests":"yarn jest --testPathPattern=e2e",
17+
"pree2e":"yarn build",
18+
"e2e":"yarn jest --testPathPattern=e2e",
1919
"debug":"node -r dotenv-flow/config src/tmp/debug.js",
20-
"prepublish":"yarn e2e-tests"
20+
"prepublish":"yarn e2e"
2121
},
2222
"lint-staged": {
2323
"*.{ts,css,md}":"prettier --write"

‎src/__generated__/index.ts‎

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎src/github-blog.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import { GraphQLClient } from "graphql-request";
22
import{GithubQueryArgs,githubQueryBuilder}from"./utils/github-query";
33
import{PagerArgs,buildPager}from"./utils/pager";
44

5+
import{getSdk}from"./core/sdk";
6+
57
import{getPosts}from"./methods/getPosts";
8+
import{getPinnedPosts}from"./methods/getPinnedPosts";
69
import{getPost}from"./methods/getPost";
710
import{getComments}from"./methods/getComments";
811
import{getLabels}from"./methods/getLabels";
912

10-
import{getSdk}from"./core/sdk";
11-
1213
exporttypeGithubBlogParams={
1314
token:string;
1415
repo:string;
@@ -37,4 +38,5 @@ export class GithubBlog {
3738
getPost=getPost(this);
3839
getComments=getComments(this);
3940
getLabels=getLabels(this);
41+
getPinnedPosts=getPinnedPosts(this);
4042
}

‎src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export{GithubBlog}from"./github-blog";
2-
export{ReactionType}from"./datatypes/Reactions";
2+
export*from"./public-types";

‎src/methods/getPinnedPosts.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import{gql}from"graphql-request";
2+
importtype{GithubBlog}from"../github-blog";
3+
import{isNonNull}from"../utils/func";
4+
import{PostReduced}from"../datatypes/PostReduced";
5+
import{Author}from"../datatypes/Author";
6+
7+
gql`
8+
query GetPinnedPosts($owner: String!, $name: String!) {
9+
repository(owner: $owner, name: $name) {
10+
pinnedIssues(first: 3) {
11+
nodes {
12+
pinnedBy {
13+
...Author_Actor
14+
}
15+
issue {
16+
...Post_Issue
17+
}
18+
}
19+
}
20+
}
21+
}
22+
`;
23+
24+
exportconstgetPinnedPosts=(blog:GithubBlog)=>async()=>{
25+
const[owner,name]=blog.repo.split("/");
26+
27+
constresult=awaitblog.sdk.GetPinnedPosts({ owner, name});
28+
constnodes=result.repository?.pinnedIssues?.nodes??[];
29+
30+
return{
31+
pinnedPosts:nodes.filter(isNonNull).map((pinnedIssue)=>({
32+
pinnedBy:Author.translate(pinnedIssue.pinnedBy),
33+
post:PostReduced.translate(pinnedIssue.issue),
34+
})),
35+
};
36+
};

‎src/public-types.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* Datatypes Types */
2+
3+
import{Author}from"./datatypes/Author";
4+
exporttypeAuthor=typeofAuthor.Type;
5+
6+
import{Comment}from"./datatypes/Comment";
7+
exporttypeComment=typeofComment.Type;
8+
9+
import{Label}from"./datatypes/Label";
10+
exporttypeLabel=typeofLabel.Type;
11+
12+
import{Labels}from"./datatypes/Labels";
13+
exporttypeLabels=typeofLabels.Type;
14+
15+
import{Post}from"./datatypes/Post";
16+
exporttypePost=typeofPost.Type;
17+
18+
import{PostReduced}from"./datatypes/PostReduced";
19+
exporttypePostReduced=typeofPostReduced.Type;
20+
21+
import{Reactions}from"./datatypes/Reactions";
22+
exporttypeReactions=typeofReactions.Type;
23+
24+
/* Methods Types */
25+
26+
import{getComments}from"./methods/getComments";
27+
exporttypeGetComments=ReturnType<typeofgetComments>;
28+
exporttypeGetCommentsParams=Parameters<GetComments>[0];
29+
exporttypeGetCommentsResult=ReturnType<GetComments>;
30+
31+
import{getLabels}from"./methods/getLabels";
32+
exporttypeGetLabels=ReturnType<typeofgetLabels>;
33+
exporttypeGetLabelsParams=Parameters<GetLabels>[0];
34+
exporttypeGetLabelsResult=ReturnType<GetLabels>;
35+
36+
import{getPinnedPosts}from"./methods/getPinnedPosts";
37+
exporttypeGetPinnedPosts=ReturnType<typeofgetPinnedPosts>;
38+
exporttypeGetPinnedPostsParams=undefined;
39+
exporttypeGetPinnedPostsResult=ReturnType<GetPinnedPosts>;
40+
41+
import{getPost}from"./methods/getPost";
42+
exporttypeGetPost=ReturnType<typeofgetPost>;
43+
exporttypeGetPostParams=Parameters<GetPost>[0];
44+
exporttypeGetPostResult=ReturnType<GetPost>;
45+
46+
import{getPosts}from"./methods/getPosts";
47+
exporttypeGetPosts=ReturnType<typeofgetPosts>;
48+
exporttypeGetPostsParams=Parameters<GetPosts>[0];
49+
exporttypeGetPostsResult=ReturnType<GetPosts>;

‎tsconfig.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
"baseUrl":"./src"
1616
},
1717
"include": ["types/*.d.ts","__generated__/*.d.ts","**/*.ts","**/*.tsx"],
18-
"exclude": ["node_modules","src/tmp","tmp","dist","end-to-end-tests"]
18+
"exclude": ["node_modules","src/tmp","tmp","dist","e2e"]
1919
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp