rm ratelimit

pull/4791/head
filip mertens 5 months ago
parent 597a559992
commit 86ebcd0c1e
  1. 54
      apps/remix-ide/src/app/files/dgitProvider.ts
  2. 4
      libs/remix-ui/git/src/components/github/devicecode.tsx
  3. 12
      libs/remix-ui/git/src/lib/gitactions.ts
  4. 6
      libs/remix-ui/git/src/state/gitpayload.ts
  5. 7
      libs/remix-ui/git/src/state/gitreducer.tsx
  6. 3
      libs/remix-ui/git/src/types/index.ts

@ -19,7 +19,7 @@ import { Octokit, App } from "octokit"
import { OctokitResponse } from '@octokit/types'
import { Endpoints } from "@octokit/types"
import { IndexedDBStorage } from './filesystems/indexedDB'
import { GitHubUser, RateLimit, branch, commitChange, remote, pagedCommits, remoteCommitsInputType, cloneInputType, fetchInputType, pullInputType, pushInputType, currentBranchInput, branchInputType, addInput, rmInput, resolveRefInput, readBlobInput, repositoriesInput, commitInput, branchDifference, compareBranchesInput, initInput, userEmails } from '@remix-ui/git'
import { GitHubUser, branch, commitChange, remote, pagedCommits, remoteCommitsInputType, cloneInputType, fetchInputType, pullInputType, pushInputType, currentBranchInput, branchInputType, addInput, rmInput, resolveRefInput, readBlobInput, repositoriesInput, commitInput, branchDifference, compareBranchesInput, initInput, userEmails } from '@remix-ui/git'
import { LibraryProfile, StatusEvents } from '@remixproject/plugin-utils'
import { ITerminal } from '@remixproject/plugin-api/src/lib/terminal'
@ -252,7 +252,7 @@ class DGitProvider extends Plugin {
this.emit('checkout')
}
async log(cmd:{ref:string}):Promise<ReadCommitResult[]> {
async log(cmd: { ref: string }): Promise<ReadCommitResult[]> {
if ((Registry.getInstance().get('platform').api.isDesktop())) {
const status = await this.call('isogit', 'log', {
@ -362,8 +362,7 @@ class DGitProvider extends Plugin {
let remotes: remote[] = []
try {
remotes = (await git.listRemotes({ ...config ? config : await this.addIsomorphicGitConfigFS() })).map((remote) =>
{ return { name: remote.remote, url: remote.url } }
remotes = (await git.listRemotes({ ...config ? config : await this.addIsomorphicGitConfigFS() })).map((remote) => { return { name: remote.remote, url: remote.url } }
)
} catch (e) {
// do nothing
@ -573,7 +572,7 @@ class DGitProvider extends Plugin {
const result = await this.call('isogit', 'clone', cmd)
this.call('fs', 'openWindow', folder)
return result
} catch (e){
} catch (e) {
this.call('notification', 'alert', {
id: 'dgitAlert',
message: 'Unexpected error while cloning the repository: \n' + e.toString(),
@ -710,8 +709,9 @@ class DGitProvider extends Plugin {
this.call('terminal', 'log', {
type: 'error',
value: `Could not checkout submodule to ${result[0]}`
})} else {
this.call('terminal', 'logHtml',`Checked out submodule ${dir} to ${result[0]}`)
})
} else {
this.call('terminal', 'logHtml', `Checked out submodule ${dir} to ${result[0]}`)
}
}
@ -1004,37 +1004,29 @@ class DGitProvider extends Plugin {
async getGitHubUser(input: { token: string }): Promise<{
user: GitHubUser,
ratelimit: RateLimit,
emails: userEmails,
scopes: string[]
}> {
const octokit = new Octokit({
auth: input.token
})
const ratelimit = await octokit.request('GET /rate_limit', {
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})
// epoch timestamp to local date time
const localResetTime = ratelimit.data.rate.reset * 1000
const localResetTimeString = new Date(localResetTime).toLocaleString()
console.log('rate limit', localResetTimeString)
try {
console.log('getGitHubUser', input)
const octokit = new Octokit({
auth: input.token
})
const user = await octokit.request('GET /user')
const emails = await octokit.request('GET /user/emails')
const user = await octokit.request('GET /user')
const emails = await octokit.request('GET /user/emails')
const scopes = user.headers['x-oauth-scopes'];
const scopes = user.headers['x-oauth-scopes'];
console.log('scopes', scopes)
console.log('scopes', scopes)
return {
user: user.data,
emails: emails.data,
ratelimit: ratelimit.data,
scopes: scopes.split(',')
return {
user: user.data,
emails: emails.data,
scopes: scopes.split(',')
}
} catch (e) {
return null
}
}

@ -83,10 +83,6 @@ export const GetDeviceCode = () => {
}, [])
useEffect(() => {
console.log('context.rateLimit', context.rateLimit)
}, [context.rateLimit])
return (
<>
{(context.gitHubUser && context.gitHubUser.login) ? null :

@ -1,8 +1,8 @@
import { ViewPlugin } from "@remixproject/engine-web";
import { ReadBlobResult, ReadCommitResult } from "isomorphic-git";
import React from "react";
import { fileStatus, fileStatusMerge, setRemoteBranchCommits, resetRemoteBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRateLimit, setRemoteBranches, setRemotes, setRepos, setUpstream, setLocalBranchCommits, setBranchDifferences, setRemoteAsDefault, setScopes, setLog, clearLog, setUserEmails } from "../state/gitpayload";
import { GitHubUser, RateLimit, branch, commitChange, gitActionDispatch, statusMatrixType, gitState, branchDifference, remote, gitLog, fileStatusResult, customGitApi, IGitApi, cloneInputType, fetchInputType, pullInputType, pushInputType, checkoutInput, rmInput, addInput, repository, userEmails } from '../types';
import { fileStatus, fileStatusMerge, setRemoteBranchCommits, resetRemoteBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRemoteBranches, setRemotes, setRepos, setUpstream, setLocalBranchCommits, setBranchDifferences, setRemoteAsDefault, setScopes, setLog, clearLog, setUserEmails } from "../state/gitpayload";
import { GitHubUser, branch, commitChange, gitActionDispatch, statusMatrixType, gitState, branchDifference, remote, gitLog, fileStatusResult, customGitApi, IGitApi, cloneInputType, fetchInputType, pullInputType, pushInputType, checkoutInput, rmInput, addInput, repository, userEmails } from '../types';
import { removeSlash } from "../utils";
import { disableCallBacks, enableCallBacks } from "./listeners";
import { AlertModal, ModalTypes } from "@remix-ui/app";
@ -510,11 +510,7 @@ export const remoteCommits = async (url: string, branch: string, length: number)
})
}
} catch (e) {
console.log(e)
plugin.call('notification', 'alert', {
title: 'Error',
message: e.message
})
// do nothing
}
}
@ -557,7 +553,6 @@ export const loadGitHubUserFromToken = async () => {
if (token) {
const data: {
user: GitHubUser,
ratelimit: RateLimit
scopes: string[]
emails: userEmails
} = await plugin.call('dgitApi' as any, 'getGitHubUser', { token });
@ -572,7 +567,6 @@ export const loadGitHubUserFromToken = async () => {
if (data.user && data.user.login && (storedUsername !== data.user.login)) await plugin.call('config', 'setAppParameter', 'settings/github-user-name', data.user.login)
dispatch(setGitHubUser(data.user))
dispatch(setRateLimit(data.ratelimit))
dispatch(setScopes(data.scopes))
dispatch(setUserEmails(data.emails))

@ -59,12 +59,6 @@ export const setUserEmails = (emails: userEmails) => {
}
}
export const setRateLimit = (rateLimit: any) => {
return {
type: 'SET_RATE_LIMIT',
payload: rateLimit
}
}
export const setScopes = (scopes: string[]) => {
return {

@ -157,13 +157,6 @@ export const gitReducer = (state: gitState = defaultGitState, action: Actions):
gitHubUser: action.payload
}
case 'SET_RATE_LIMIT':
console.log("rate limit", action.payload)
return {
...state,
rateLimit: action.payload
}
case 'SET_GITHUB_ACCESS_TOKEN':
return {
...state,

@ -3,7 +3,6 @@ import { IRemixApi } from "@remixproject/plugin-api"
import { LibraryProfile, StatusEvents } from "@remixproject/plugin-utils"
import { CommitObject, ReadBlobResult, ReadCommitResult, StatusRow } from "isomorphic-git"
export type GitHubUser = Partial<Endpoints["GET /user"]["response"]['data']>
export type RateLimit = Endpoints["GET /rate_limit"]["response"]["data"]
export type userEmails = Endpoints["GET /user/emails"]["response"]["data"]
export interface IGitApi {
@ -179,7 +178,6 @@ export type gitState = {
remoteCommitCount: number
upstream: remote
gitHubUser: GitHubUser
rateLimit: RateLimit
userEmails: userEmails
gitHubScopes: string[]
gitHubAccessToken: string
@ -293,7 +291,6 @@ export const defaultGitState: gitState = {
remoteCommitCount: 0,
upstream: null,
gitHubUser: {} as GitHubUser,
rateLimit: {} as RateLimit,
userEmails: [] as userEmails,
gitHubScopes: [],
gitHubAccessToken: "",

Loading…
Cancel
Save