-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepostioryAction.js
More file actions
133 lines (132 loc) · 3 KB
/
RepostioryAction.js
File metadata and controls
133 lines (132 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import {
GET_REPOSITORIES,
GET_COMMITS,
REFERSH_COMMITS,
NO_ITEMS_AVAILABLE
} from "./Type";
import { API_CONFIGURATION } from "../Constants";
/**
*
* @param {string} token toke for fetching repo
*/
export const getRepositories = token => dispatch => {// arrow function feature of ES6 ..Why:clean code..better readability
fetch(
API_CONFIGURATION.URL +//github base url
"/" +
"users" +
"/" +
API_CONFIGURATION.REPO_NAME +//main repo or user name hard coded to facebook right now
"/" +
API_CONFIGURATION.REPO_CONTEXT +
"?" +
API_CONFIGURATION.ACCESS_TOKEN_LABEL +
"=" +
token
)
.then(res => res.json())
.then(response =>
dispatch({
type: GET_REPOSITORIES,
payload: response
})
);
};
/**
*
* @param {string} token token for gitub repo not implemeted now
* @param {string} repositoryName repository name for fetching commits
* @param {number} page page number for pagiation
* @param {number} pageSize optional
*/
export const getCommits = (
token,
repositoryName,
page = 1,//defalut parameter feature of ES6 to assign a default value...Why : simplifirs the code..avoids sending values all the time and adds the flexibility to send custom values
pageSize = 20
) => dispatch => {
fetch(
API_CONFIGURATION.URL +
"/" +
API_CONFIGURATION.REPO_CONTEXT +
"/" +
API_CONFIGURATION.REPO_NAME +
"/" +
repositoryName +
"/" +
API_CONFIGURATION.COMMIT_CONTEXT +
"?page=" +
page +
"&per_page=" +
pageSize +
"&access_token=" +
token
)
.then(res => res.json())
.then(response => {
debugger;
response && response.length > 0
? dispatch({
type: GET_COMMITS,
payload: response
})
: dispatch({
type: NO_ITEMS_AVAILABLE,
payload: false
});
});
};
/**refersh commits from the UI */
export const refreshCommits = () => dispatch => {
dispatch({
type: REFERSH_COMMITS,
payload: []
});
};
/**
*
* @param {string} user main owner
* @param {string} repoName reponame
* @param {string} search search string
* @param {number} page page number
* @param {number} sizePage size of the page
*/
export const searchCommits = (
user,
repoName,
search,
page = 1,
sizePage = 20
) => dispatch => {
fetch(
API_CONFIGURATION.URL +
"/" +
API_CONFIGURATION.SEARCH_COMMITS +
"?page=" +
page +
"&per_page=" +
sizePage +
"&q=repo:" +
user +
"/" +
repoName +
"+" +
search,
{
headers: {
Accept: "application/vnd.github.cloak-preview"
}
}
)
.then(res => res.json())
.then(response => {
response.items && response.items.length > 0
? dispatch({
type: GET_COMMITS,
payload: response.items
})
: dispatch({
type: NO_ITEMS_AVAILABLE,
payload: false
});
});
};