小编Sim*_*aud的帖子

gitlab - 使用access_token推送到存储库

我实现了oauth2 web流程,以便从我的app的用户那里获取access_token.通过access_token,我想执行以下操作:

  • 1.获取用户信息
  • 2.为该用户创建一个仓库
  • 3.将代码推送到此仓库(使用git push)

我已经成功获取用户信息(1)并创建了一个仓库(2)

问题是我无法推送代码(3),我收到"未经授权"的错误.


我运行的命令:

git remote add origin https://gitlab-ci-token:<mytoken>@gitlab.com/myuser/myrepo.git
git push origin master
最好的祝福.

git push oauth token gitlab

10
推荐指数
3
解决办法
7165
查看次数

在缓存类型策略中添加嵌套字段 - Apollo v3

我想知道是否可以使用 InMemoryCache 的 typePolicies 来嵌套值 现在您可以定义平面字段策略

new InMemoryCache({
  typePolicies: {
    Query: {
      fields: {
        hello: {
          read() {
            return 'hello'
          },
        },
        hola: {
          read() {
            return 'hola'
          },
        },
      },
    },
  },
})

// query flat local field using apollo
const QUERY_USER_PAGE = gql`
  query UserPage {
      hello
      hola
  }
`
Run Code Online (Sandbox Code Playgroud)

如果我想要反映我的应用程序结构的 typePolicies 该怎么办,这似乎是一个很好的做法。
扁平结构在大型项目的扩展和维护方面会受到限制。

new InMemoryCache({
  typePolicies: {
    Query: {
      fields: {
        userPage: {
          hello: {
            read() {
              return 'hello'
            },
          },
          hola: {
            read() {
              return 'hola' …
Run Code Online (Sandbox Code Playgroud)

javascript typescript apollo react-apollo apollo-client

8
推荐指数
1
解决办法
1021
查看次数

如何使用 jest/enzyme 正确测试依赖于 useState 的受控输入组件

我想使用 Jest/enzyme 测试受控组件。

我有一个<Input>给定的组件max,并且props 会在触发事件min时自动完成该值change

// Input.tsx
const Input = ({value, onChange, max, min}) => {

  const handleChange = (evt) => {
    const newValue = Number(evt.target.value)

    if(min !== undefined && newValue < min) {
      onChange(min)
      return 
    }

    if(max !== undefined && newValue > max) {
      onChange(max)
      return
    }

    onChange(newValue)
  }

  return (
    <div>
      <label>My input</label>
      <input type="number" value={value} onChange={handleChange} />
    </div>
  )
}
Run Code Online (Sandbox Code Playgroud)

我想用玩笑来测试该组件及其不同的change用例。
因为它是一个完全受控的组件,所以我开始编写以下代码:

    const onChangeSpy = jest.fn()
    const Wrapper …
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs jestjs enzyme

7
推荐指数
0
解决办法
1787
查看次数

Promise.allSettled 打字稿数组推理

我希望 Typescript 推断过滤数组上的类型。

我根据“已拒绝”或“已完成”状态(来自 Promise.allSettled)过滤结果。

由于某种原因,Typescript 无法推断我的过滤结果。
这是我想要实现的目标的一个最小示例:

type FullFilledResults = {
  status: 'fullfilled';
  value: any;
}

type RejectResults = {
  status: 'rejected';
  reason: string;
}

type Results = RejectResults | FullFilledResults

const results: Results[] = [{
  status: 'rejected',
  reason: 'err'
}, {
  status: 'fullfilled',
  value: {}
}]

// Type infer Results[] but I want FullFilledResults[]
const fullfilledResults = results.filter(v => v.status === 'fullfilled')

// Type infer Results[] but I want RejectedResults[]
const rejectedResults = results.filter(v => v.status === 'rejected')
Run Code Online (Sandbox Code Playgroud)

javascript type-inference promise typescript

6
推荐指数
2
解决办法
4332
查看次数

当gitlab-CI管道失败时阻止提交

如果管道出现故障,有没有办法防止推送到gitlab?

这是一个包含多个作业的gitlab-ci.yml示例.每次推送都会触发此管道.

如果其中一个作业失败,我不希望我的代码被推送到我的存储库.(我知道拉取请求存在此功能).

image: node:9.4.0

cache:
  paths:
  - node_modules/

before_script:
  - npm install

stages:
    - lint
    - test

lint:
  stage: lint
  script:
   - npm run lint

test:
  stage: test
  script:
   - npm run test
Run Code Online (Sandbox Code Playgroud)

git testing push gitlab gitlab-ci

3
推荐指数
1
解决办法
3796
查看次数