Skip to content

Commit 8a64611

Browse files
committed
fix storage issues
1 parent cd75d83 commit 8a64611

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

src/content.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function buildUrl({base, q: {type, filterUser, author, repo}, sort, order, per_p
4747
return query;
4848
}
4949

50-
function contributorCount({access_token, contributor, repoPath, type}) {
50+
function contributorCount({access_token, contributor, repoPath, old = {}, type}) {
5151
let searchURL = buildUrl({
5252
access_token,
5353
base: "https://api.github.com/search/issues",
@@ -82,15 +82,9 @@ function contributorCount({access_token, contributor, repoPath, type}) {
8282
obj[`first${type[0].toUpperCase() + type.slice(1)}Number`] = json.items[0].number;
8383
}
8484

85-
if (obj.prs) {
86-
setStorageProperty(contributor, repoPath, "lastUpdate", obj.lastUpdate);
87-
setStorageProperty(contributor, repoPath, "prs", obj.prs);
88-
setStorageProperty(contributor, repoPath, "firstPrNumber", obj.firstPrNumber);
89-
} else if (obj.issues) {
90-
setStorageProperty(contributor, repoPath, "lastUpdate", obj.lastUpdate);
91-
setStorageProperty(contributor, repoPath, "issues", obj.issues);
92-
setStorageProperty(contributor, repoPath, "firstIssueNumber", obj.firstIssueNumber);
93-
}
85+
obj = Object.assign(old, obj);
86+
87+
setStorage(contributor, repoPath, obj);
9488

9589
return obj;
9690
});
@@ -182,8 +176,8 @@ function update({ contributor, repoPath, currentNum }) {
182176
getSyncStorage({ "access_token": null })
183177
.then((res) => {
184178
Promise.all([
185-
contributorCount({ access_token: res.access_token, type: "pr", contributor, repoPath}),
186-
contributorCount({ access_token: res.access_token, type: "issue", contributor, repoPath})
179+
contributorCount({ old: storageRes, access_token: res.access_token, type: "pr", contributor, repoPath}),
180+
contributorCount({ old: storageRes, access_token: res.access_token, type: "issue", contributor, repoPath})
187181
])
188182
.then(([prInfo, issueInfo]) => {
189183
let repoInfo = Object.assign(prInfo, issueInfo);

src/storage.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ window.setStorage = (CONTRIBUTOR, ORG_REPO_PATH, value) => {
3434
});
3535
};
3636

37-
window.setStorageProperty = (CONTRIBUTOR, ORG_REPO_PATH, prop, value) => {
38-
return window.setSyncStorage({
39-
[CONTRIBUTOR]: {
40-
[ORG_REPO_PATH]: {
41-
[prop]: value
42-
}
43-
}
44-
});
45-
};
46-
4737
window.getStorage = (CONTRIBUTOR, ORG_REPO_PATH) => {
4838
return window.getSyncStorage({
4939
[CONTRIBUTOR]: {

0 commit comments

Comments
 (0)