nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: kibertoad/toad-scheduler
Pull request #1 (2021-01-20 02:10:34)

Prevent possibility to launch same job multiple times simultaneously


Patch:
diff --git a/lib/engines/simple-interval/SimpleIntervalJob.ts b/lib/engines/simple-interval/SimpleIntervalJob.ts
index 6cd2626..e09a79e 100644
--- a/lib/engines/simple-interval/SimpleIntervalJob.ts
+++ b/lib/engines/simple-interval/SimpleIntervalJob.ts
@@ -18,6 +18,11 @@ export class SimpleIntervalJob extends Job {
   start(): void {
     const time = toMsecs(this.schedule)
 
+    // Avoid starting duplicates and leaking previous timers
+    if (this.timer) {
+      this.stop()
+    }
+
     this.timer = setInterval(() => {
       this.task.execute()
     }, time)
diff --git a/package.json b/package.json
index 1ef7498..0adad9d 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "toad-scheduler",
-  "version": "1.0.1",
+  "version": "1.0.2",
   "license": "MIT",
   "description": "In-memory Node.js job scheduler",
   "maintainers": [


Test patch:
diff --git a/test/toadScheduler.spec.ts b/test/toadScheduler.spec.ts
index 4721d43..5799ff7 100644
--- a/test/toadScheduler.spec.ts
+++ b/test/toadScheduler.spec.ts
@@ -69,6 +69,29 @@ describe('ToadScheduler', () => {
       scheduler.stop()
     })
 
+    it('correctly handles adding job twice', () => {
+      let counter = 0
+      const scheduler = new ToadScheduler()
+      const task = new Task('simple task', () => {
+        counter++
+      })
+      const job = new SimpleIntervalJob(
+        {
+          milliseconds: 10,
+        },
+        task
+      )
+
+      scheduler.addSimpleIntervalJob(job)
+      scheduler.addSimpleIntervalJob(job)
+
+      expect(counter).toBe(0)
+      jest.advanceTimersByTime(20)
+      expect(counter).toBe(2)
+
+      scheduler.stop()
+    })
+
     it('correctly stops jobs', () => {
       let counter = 0
       const scheduler = new ToadScheduler()
Repository: kibertoad/toad-scheduler
Pull request #57 (2021-11-01 13:44:38)

Make toad-scheduler compatible with browsers again


Patch:
diff --git a/lib/common/AsyncTask.ts b/lib/common/AsyncTask.ts
index 55f4ac2..b23b950 100644
--- a/lib/common/AsyncTask.ts
+++ b/lib/common/AsyncTask.ts
@@ -1,5 +1,5 @@
 import { defaultErrorHandler, loggingErrorHandler } from './Logger'
-import { types } from 'util'
+import { isPromise } from './Utils'
 
 export class AsyncTask {
   private readonly id: string
@@ -15,7 +15,7 @@ export class AsyncTask {
   execute(): void {
     this.handler().catch((err: Error) => {
       const errorHandleResult = this.errorHandler(err)
-      if (types.isPromise(errorHandleResult)) {
+      if (isPromise(errorHandleResult)) {
         // If we fail while handling an error, oh well
         errorHandleResult.catch(loggingErrorHandler(err))
       }
diff --git a/lib/common/Task.ts b/lib/common/Task.ts
index 0605ff4..7ca1e3d 100644
--- a/lib/common/Task.ts
+++ b/lib/common/Task.ts
@@ -1,5 +1,5 @@
 import { defaultErrorHandler, loggingErrorHandler } from './Logger'
-import { types } from 'util'
+import { isPromise } from './Utils'
 
 export class Task {
   private readonly id: string
@@ -17,7 +17,7 @@ export class Task {
       this.handler()
     } catch (err: any) {
       const errorHandleResult = this.errorHandler(err)
-      if (types.isPromise(errorHandleResult)) {
+      if (isPromise(errorHandleResult)) {
         // If we fail while handling an error, oh well
         errorHandleResult.catch(loggingErrorHandler(err))
       }
diff --git a/lib/common/Utils.ts b/lib/common/Utils.ts
new file mode 100644
index 0000000..f40f909
--- /dev/null
+++ b/lib/common/Utils.ts
@@ -0,0 +1,3 @@
+export function isPromise(value: any): value is Promise<any> {
+  return value && value.then !== undefined ? true : false
+}


Test patch:
diff --git a/test/Utils.spec.ts b/test/Utils.spec.ts
new file mode 100644
index 0000000..0a42d47
--- /dev/null
+++ b/test/Utils.spec.ts
@@ -0,0 +1,24 @@
+import { isPromise } from '../lib/common/Utils'
+
+describe('Utils', () => {
+  describe('isPromise', () => {
+    it('Correctly identifies promise', () => {
+      const promise = Promise.resolve().then(() => {
+        return true
+      })
+      const promise2 = Promise.resolve()
+      expect(isPromise(promise)).toEqual(true)
+      expect(isPromise(promise2)).toEqual(true)
+    })
+
+    it('Correctly identifies not promise', () => {
+      expect(isPromise(null)).toEqual(false)
+      expect(isPromise(undefined)).toEqual(false)
+      expect(isPromise(0)).toEqual(false)
+      expect(isPromise(1)).toEqual(false)
+      expect(isPromise({})).toEqual(false)
+      expect(isPromise(() => {})).toEqual(false)
+      expect(isPromise('text')).toEqual(false)
+    })
+  })
+})
Repository: Yoctol/bottender
Pull request #7 (2017-11-06 06:59:02)

prevent restify slack webhook verifacation next()
`url_verification` events should not go next()


Patch:
diff --git a/src/restify/verifySlackWebhook.js b/src/restify/verifySlackWebhook.js
index da64e194..60a8807e 100644
--- a/src/restify/verifySlackWebhook.js
+++ b/src/restify/verifySlackWebhook.js
@@ -5,9 +5,9 @@ const verifySlackWebhook = () => (req, res, next) => {
     res.end(req.params.challenge);
   } else if (body && body.type && body.type === 'url_verification') {
     res.end(req.body.challenge);
+  } else {
+    return next();
   }
-
-  return next();
 };
 
 export default verifySlackWebhook;


Test patch:
diff --git a/src/restify/__tests__/verifySlackWebhook.spec.js b/src/restify/__tests__/verifySlackWebhook.spec.js
index bae44f52..1f67f6ef 100644
--- a/src/restify/__tests__/verifySlackWebhook.spec.js
+++ b/src/restify/__tests__/verifySlackWebhook.spec.js
@@ -31,7 +31,7 @@ it('should correctly response the challenge is an url_verification event', () =>
   expect(response.end).toBeCalledWith(
     'kImeZUaSI0jJLowDasma5WEiffaScgsjnINWDlpapA9fB7uCB36d'
   );
-  expect(next).toBeCalled();
+  expect(next).not.toBeCalled();
 });
 
 it('responds with success to url_verification event in body', () => {
@@ -45,7 +45,7 @@ it('responds with success to url_verification event in body', () => {
   expect(response.end).toBeCalledWith(
     'kImeZUaSI0jJLowDasma5WEiffaScgsjnINWDlpapA9fB7uCB36d'
   );
-  expect(next).toBeCalled();
+  expect(next).not.toBeCalled();
 });
 
 it('should only call next when request is not an url_verification event', () => {
Repository: Yoctol/bottender
Pull request #52 (2017-11-30 04:22:34)

support line client reply() push()
so we can do 
```js
const { Line } = require('messaging-api-line')
await context.reply([Line.createText('aaa'), Line.createText('bbb')])
await context.push([Line.createText('aaa'), Line.createText('bbb')])
```
which is useful for reply-only LINE bots.


Patch:
diff --git a/src/context/LineContext.js b/src/context/LineContext.js
index 64d9c5d3..aa7a20f4 100644
--- a/src/context/LineContext.js
+++ b/src/context/LineContext.js
@@ -117,6 +117,7 @@ class LineContext extends Context implements PlatformContext {
 }
 
 const types = [
+  '',
   'Text',
   'Image',
   'Video',
@@ -167,7 +168,7 @@ types.forEach(type => {
   });
 });
 
-types.filter(type => type !== 'Text').forEach(type => {
+types.filter(type => type !== 'Text' && type !== '').forEach(type => {
   Object.defineProperty(LineContext.prototype, `send${type}`, {
     enumerable: false,
     configurable: true,


Test patch:
diff --git a/src/context/__tests__/LineContext.spec.js b/src/context/__tests__/LineContext.spec.js
index aa1c6b73..da1a668e 100644
--- a/src/context/__tests__/LineContext.spec.js
+++ b/src/context/__tests__/LineContext.spec.js
@@ -39,7 +39,9 @@ const userSession = {
 };
 const setup = ({ session } = { session: userSession }) => {
   const client = {
+    reply: jest.fn(),
     replyText: jest.fn(),
+    push: jest.fn(),
     pushText: jest.fn(),
     pushImage: jest.fn(),
     pushAudio: jest.fn(),
@@ -97,6 +99,24 @@ it('get #client works', () => {
 });
 
 describe('#reply', () => {
+  it('#reply to call client.reply', async () => {
+    const { context, client } = setup();
+
+    await context.reply([
+      {
+        type: 'text',
+        text: 'xxx.com',
+      },
+    ]);
+
+    expect(client.reply).toBeCalledWith(rawEvent.replyToken, [
+      {
+        type: 'text',
+        text: 'xxx.com',
+      },
+    ]);
+  });
+
   it('#replyText to call client.replyText', async () => {
     const { context, client } = setup();
 
@@ -133,6 +153,14 @@ describe('#reply', () => {
   });
 });
 
+describe('#send', () => {
+  it('is not defined', () => {
+    const { context } = setup();
+
+    expect(context.send).not.toBeDefined();
+  });
+});
+
 describe('#sendText', () => {
   it('should call client.pushText', async () => {
     const { context, client, session } = setup();
@@ -171,6 +199,26 @@ describe('#sendText', () => {
   });
 });
 
+describe('#push', () => {
+  it('should call client.push', async () => {
+    const { context, client, session } = setup();
+
+    await context.push([
+      {
+        type: 'text',
+        text: 'xxx.com',
+      },
+    ]);
+
+    expect(client.push).toBeCalledWith(session.user.id, [
+      {
+        type: 'text',
+        text: 'xxx.com',
+      },
+    ]);
+  });
+});
+
 describe('#pushText', () => {
   it('should call client.pushText', async () => {
     const { context, client, session } = setup();